:root {
  --page: #dde7f0;
  --ink: #14233a;
  --muted: #4b5d75;
  --key: #ffc400;
  --casing: #2b3038;
  --casing-edge: #181b20;
  --lcd: #07182b;
  --lcd-text: #cfe8ff;
  --alert: #b3261e;
  --field: #f7fafc;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 17px/1.6 "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

h1 { margin: 0; font-size: 30px; line-height: 1.25; font-weight: 800; }
.lead { margin: 6px 0 24px; color: var(--muted); }

.field { display: block; margin: 0 0 16px; padding: 0; border: 0; }
.field > span, .field > legend { display: block; margin-bottom: 6px; padding: 0; font-weight: 700; }

input[type="password"], select, textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
}
textarea { resize: vertical; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 11px; text-align: center; font-weight: 700; background: var(--field); cursor: pointer; }
.segmented input:checked + span { background: var(--ink); color: #fff; }
.segmented input:focus-visible + span { outline: 3px solid var(--key); outline-offset: -5px; }

.examples { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 16px; }
.examples button {
  min-height: 40px;
  padding: 4px 12px;
  border: 1px solid var(--muted);
  border-radius: 20px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}

.primary {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-bottom: 4px solid #b98e00;
  border-radius: 8px;
  background: var(--key);
  color: var(--ink);
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
}
.primary:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; }
.primary:disabled { opacity: .65; cursor: progress; }

.error { margin: 12px 0 0; color: var(--alert); font-weight: 700; }

/* The result is drawn as an M5Stack: the three actions sit where buttons A, B and C do. */
.device {
  margin-top: 28px;
  padding: 14px 14px 0;
  border-radius: 18px;
  background: var(--casing);
  box-shadow: 0 6px 0 var(--casing-edge);
}
.screen { border: 6px solid #000; border-radius: 6px; background: var(--lcd); }
#code {
  height: 340px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  color: var(--lcd-text);
  font: 14px/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
  tab-size: 4;
}
#code:focus-visible { outline: 3px solid var(--key); outline-offset: -3px; }

.device-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 14px 0; }
.device-buttons button {
  min-height: 48px;
  padding: 4px;
  border: 0;
  border-bottom: 4px solid #000;
  border-radius: 6px;
  background: #4a515c;
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.device-buttons button:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; }
.device-buttons button:disabled { opacity: .45; cursor: default; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}
.device-buttons button:focus-visible { outline-color: var(--key); }

.explanation { margin-top: 22px; white-space: pre-wrap; }
.explanation:empty { display: none; }

.howto { margin-top: 22px; border-top: 2px solid var(--ink); padding-top: 12px; }
.howto summary { font-weight: 700; cursor: pointer; min-height: 32px; }
.howto ol { margin: 8px 0 0; padding-left: 24px; }

@media (prefers-reduced-motion: reduce) {
  .primary:active:not(:disabled), .device-buttons button:active:not(:disabled) { transform: none; }
}
