:root {
  color-scheme: light;
  touch-action: manipulation;
  font-family: Futura, sans-serif;
  color: #23211f;
  background: #fff;
  --ink: #23211f;
  --soft-ink: #57534f;
  --unvisited-ink: #28704b;
  --key-border: #c7c4bf;
  --focus: #604f74;
}
* { box-sizing: border-box; }
body { margin: 0; background: #fff; touch-action: manipulation; }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
#game {
  width: min(100%, 688px);
  margin: 0 auto;
  padding: clamp(20px, 4.5vh, 44px) clamp(10px, 3.4vw, 24px) calc(max(25px, env(safe-area-inset-bottom)) + 30px);
  text-align: center;
}
.heading { margin: 0 0 6px; }
.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.6vw, 12px);
}
.title-row h1 { min-width: 0; }
.game-logo {
  display: block;
  width: clamp(32px, 3.6vw, 44px);
  height: auto;
  margin: 0;
  flex: none;
}
h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 44px);
  line-height: 1.09;
  letter-spacing: -.045em;
  font-weight: 500;
}
.room-name {
  position: relative;
  display: inline-grid;
  align-items: center;
  max-width: 100%;
  margin-top: 8px;
}
#level-select {
  appearance: none;
  /* Keep native selection, but block viewport gestures on this control. */
  touch-action: none;
  field-sizing: content;
  max-width: 100%;
  min-width: 64px;
  min-height: 36px;
  padding: 4px 22px 4px 8px;
  font-size: clamp(18px, 2.5vw, 22px);
  line-height: 1.15;
  text-align: center;
  text-align-last: center;
  color: var(--soft-ink);
  background: transparent;
  border: 0;
  border-radius: 3px;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
#level-select option { color: var(--ink); background-color: #fff; }
#level-select optgroup { color: var(--soft-ink); background-color: #fff; }
.room-name svg {
  position: absolute; right: 3px; top: 50%;
  width: 14px; height: 14px; transform: translateY(-50%);
  pointer-events: none; color: #67625d;
}
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.timeline { margin: 0 0 20px; }
.readings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 340px);
  margin: 0 auto;
  gap: 24px;
  font-variant-numeric: tabular-nums;
}
.time-reading { display: flex; flex-direction: column; align-items: center; gap: 3px; white-space: nowrap; }
.time-label {
  font-size: clamp(11px, 2.4vw, 12px);
  line-height: 1.3;
  letter-spacing: .08em;
  font-weight: 600;
  color: var(--soft-ink);
}
.readings strong { font-size: clamp(32px, 6.5vw, 42px); font-weight: 600; line-height: 1.1; }
#world-time.unvisited { color: var(--unvisited-ink); }
#personal-time.away { color: #b63738; }
#level-select:hover { background-color: #f5f4f2; }
#board-wrap { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; min-width: 0; }
#gameCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  touch-action: manipulation;
  outline: none;
}
.controls-area {
  /* Enlarge the compact layout only when both width and height permit it. */
  --control-scale: 1;
  --control-extra-gap: 0px;
  --arrow-size: calc(clamp(56px, calc(20vw - 8px), 72px) * var(--control-scale));
  --utility-size: calc(clamp(44px, 13vw, 50px) * var(--control-scale));
  display: none;
  grid-template-columns: repeat(2, max-content);
  justify-content: center;
  align-items: center;
  gap: clamp(16px, 6vw, 24px);
  margin-top: calc(clamp(14px, 2.4vh, 21px) + var(--control-extra-gap));
}
.keyboard-guide {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 24px;
  margin: clamp(32px, 5.5vh, 48px) 0 0;
  color: var(--soft-ink);
  font-size: clamp(15px, 3vw, 18px);
  font-style: italic;
  line-height: 1.5;
}
.keyboard-guide > span { white-space: nowrap; }
@media (hover: none) and (pointer: coarse) {
  .controls-area { display: grid; }
  .keyboard-guide { display: none; }
  #level-select { min-height: 44px; }
}
.controls-area button {
  appearance: none;
  width: var(--utility-size);
  height: var(--utility-size);
  display: grid;
  place-items: center;
  padding: 0;
  background: #f3f2ef;
  border: 1px solid var(--key-border);
  border-radius: 4px;
  box-shadow: 0 1px 0 #b8b4ae;
  color: #403c37;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.controls-area button svg { width: calc(22px * var(--control-scale)); height: calc(22px * var(--control-scale)); pointer-events: none; }
/* Labels are inside the existing touch targets; keep their dimensions. */
.controls-area button.labeled-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(2px * var(--control-scale));
}
.controls-area .control-label {
  font-size: calc(8px * var(--control-scale));
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}
.controls-area .control-icon { pointer-events: none; }

.controls-area button:disabled { opacity: .43; box-shadow: none; }
/* Touch controls keep their normal appearance while hovered or pressed. */
.movement-controls {
  display: grid;
  grid-template-columns: repeat(3, var(--arrow-size));
  grid-template-rows: repeat(2, var(--arrow-size));
  grid-template-areas: ". up wait" "left down right";
  gap: 6px;
}
.movement-controls button { width: var(--arrow-size); height: var(--arrow-size); }
.movement-controls button svg { width: calc(32px * var(--control-scale)); height: calc(32px * var(--control-scale)); }
.direction.up { grid-area: up; }
.direction.left { grid-area: left; }
.direction.down { grid-area: down; }
.direction.right { grid-area: right; }
.utility-controls { display: grid; grid-template-columns: repeat(2, var(--utility-size)); gap: 6px; }
.direction.wait { grid-area: wait; }
.time-controls { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, var(--utility-size)); gap: 6px; }
.controls-area .time-step { font-size: calc(20px * var(--control-scale)); font-weight: 600; line-height: 1; letter-spacing: normal; }
.edit-controls { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, var(--utility-size)); gap: 6px; }
.edit-controls button { background: #fff; }
#continue-button.is-complete:not(:disabled) {
  background: #28704b;
  border-color: #205c3d;
  color: #fff;
  box-shadow: 0 1px 0 #194a31;
}
.status {
  max-width: 52ch;
  min-height: 1.45em;
  margin: 16px auto 24px;
  font-size: 16px;
  line-height: 1.45;
  color: var(--soft-ink);
}
.status.unvisited { color: var(--unvisited-ink); }
.status.error { color: #b63738; }
#board-wrap.blocked canvas { animation: bump 145ms ease-out; }
@keyframes bump { 25% { transform: translateX(-2px); } 70% { transform: translateX(2px); } }
@media (max-height: 650px) and (min-width: 560px) {
  #game { padding-top: 12px; }
  h1 { font-size: 32px; }
  .game-logo { width: 32px; }
  .status { margin-top: 12px; margin-bottom: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  #board-wrap.blocked canvas { animation: none; }
}
