:root {
  --bg: #e9e6df;
  --ink: #2b2925;
  --muted: #6b675e;
  --body: #f2c94c;
  --body-edge: #d9ab26;
  --key: #2b2925;
  --key-ink: #f4f1ea;
  --warn: #8a3b12;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1c1a; --ink: #ece8df; --muted: #a8a397; --warn: #f0a070; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; line-height: 1.6;
}
main { max-width: 900px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.4rem; margin: 0 0 4px; }
h1 small { font-size: .9rem; font-weight: normal; color: var(--muted); }
h2 { font-size: 1.1rem; }
.note { margin: 0 0 12px; color: var(--muted); font-size: .9rem; }

.device {
  background: var(--body); border: 2px solid var(--body-edge); border-radius: 20px;
  padding: 16px; color: #2b2925; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.screen-wrap { position: relative; background: #2b2925; border-radius: 8px; padding: 8px; }
#screen {
  display: block; margin: 0 auto; width: 100%; height: auto;
  image-rendering: pixelated; background: #b1aea7;
}
.overlay {
  position: absolute; inset: 8px; margin: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(177, 174, 167, .92); color: #2b2925; font-size: 1.1rem;
}
.overlay.error { flex-direction: column; align-items: stretch; justify-content: flex-start; padding: 12px; overflow: auto; font-size: .9rem; }
.overlay.error pre { white-space: pre-wrap; word-break: break-all; font-size: .75rem; margin: 0; }
.overlay[hidden] { display: none; }
.crank-hint {
  margin: 8px 0 0; min-height: 1.5em; font-size: .85rem; text-align: center; visibility: hidden;
}
.crank-hint.show { visibility: visible; }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.k {
  width: 48px; height: 48px; border: 0; border-radius: 10px; background: var(--key); color: var(--key-ink);
  font-size: 1rem; font-weight: bold; cursor: pointer; touch-action: none;
}
.k.on, .k:active { transform: translateY(2px); filter: brightness(1.6); }
.dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); gap: 2px; }
.dpad .up { grid-area: 1 / 2; } .dpad .left { grid-area: 2 / 1; } .dpad .right { grid-area: 2 / 3; } .dpad .down { grid-area: 3 / 2; }
.ab { display: flex; gap: 16px; transform: rotate(-20deg); }
.ab .k { width: 60px; height: 60px; border-radius: 50%; font-size: 1.2rem; }
.crank { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#dial { width: 108px; height: 108px; cursor: grab; touch-action: none; background: rgba(255, 255, 255, .25); border-radius: 50%; }
#dock { font-size: .8rem; padding: 4px 8px; border-radius: 6px; border: 1px solid #2b2925; background: transparent; color: #2b2925; cursor: pointer; }

.menu-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.menu-label { font-size: .85rem; font-weight: bold; }
#menu { list-style: none; display: flex; gap: 8px; margin: 0; padding: 0; flex-wrap: wrap; }
#menu button, #menu label {
  display: inline-flex; align-items: center; gap: 4px; min-height: 36px; font-size: .9rem; padding: 4px 10px;
  border-radius: 6px; border: 1px solid #2b2925; background: rgba(255, 255, 255, .35); color: #2b2925; cursor: pointer;
}

.warn { color: var(--warn); font-weight: bold; }
.help table { border-collapse: collapse; }
.help th { text-align: left; padding: 2px 12px 2px 0; white-space: nowrap; vertical-align: top; }
.help td { padding: 2px 0; }
.help button { font: inherit; padding: 2px 8px; }

@media (max-width: 560px) {
  main { padding: 8px 16px; }
  .device { padding: 8px; border-radius: 14px; }
  .screen-wrap { padding: 4px; }
  .k { width: 42px; height: 42px; }
  .dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); }
  .ab { gap: 8px; }
  .ab .k { width: 50px; height: 50px; }
  #dial { width: 84px; height: 84px; }
  .controls { flex-wrap: wrap; justify-content: center; }
}
