/* Rotato — mobile-first styling. Game-Boy (DMG green) themed chrome around a pixel-art canvas.
   Layout is built for phones first; a media query relaxes sizing on larger / landscape screens. */

:root {
  --dark: #0f380f;
  --mid: #306230;
  --light: #8bac0f;
  --pale: #9bbc0f;
  --ink: #0f380f;
  --d-size: 62px;     /* d-pad button size */
  --radius: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--dark);
  color: var(--pale);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Disable iOS double-tap-to-zoom on every interactive surface (rapid arrow taps no longer
   zoom the game) while keeping taps, clicks and menu scrolling fully responsive.
   touch-action does not inherit, so it must be set on the elements that receive touches. */
button, input, .menu-content, #overlay {
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.hidden { display: none !important; }

/* ---------------- Menu screens ---------------- */
.menu-content {
  flex: 1;
  overflow-y: auto;
  padding: calc(18px + var(--safe-t)) 18px calc(18px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.title-hero { text-align: center; margin: 8vh 0 2vh; }
.logo {
  font-size: clamp(40px, 14vw, 72px);
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--pale);
  text-shadow: 3px 3px 0 var(--mid), 6px 6px 0 var(--dark);
}
.tagline { color: var(--light); font-size: 14px; margin-top: 6px; }

.menu-nav, .menu-list { display: flex; flex-direction: column; gap: 12px; }

.big-btn {
  appearance: none;
  border: 3px solid var(--dark);
  background: var(--light);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 16px 18px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--mid);
  transition: transform .05s, box-shadow .05s;
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--mid); }
.big-btn-sub { font-size: 14px; opacity: .75; font-weight: 600; }

.menu-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.menu-head h2 { margin: 0; font-size: 22px; color: var(--pale); }
.menu-sub { color: var(--light); margin: 0; }

.icon-btn {
  appearance: none; border: 3px solid var(--dark); background: var(--light); color: var(--ink);
  width: 42px; height: 42px; border-radius: var(--radius); font-size: 24px; font-weight: 800;
  cursor: pointer; line-height: 1; box-shadow: 0 3px 0 var(--mid);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--mid); }

.lang-row, .tabs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip {
  appearance: none; border: 2px solid var(--light); background: transparent; color: var(--pale);
  border-radius: 20px; padding: 7px 16px; font: inherit; font-weight: 700; cursor: pointer;
}
.chip.active { background: var(--light); color: var(--ink); }
.version { text-align: center; color: var(--mid); font-size: 12px; margin-top: auto; }

/* Floor grid */
.floor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.floor-tile {
  appearance: none; border: 3px solid var(--dark); background: var(--light); color: var(--ink);
  border-radius: var(--radius); padding: 12px 10px; font: inherit; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; text-align: left; box-shadow: 0 4px 0 var(--mid);
}
.floor-tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--mid); }
.floor-tile.locked { background: var(--mid); color: var(--light); box-shadow: none; cursor: default; }
.floor-tile.cleared { outline: 3px solid var(--pale); outline-offset: -3px; }
.floor-num { font-size: 22px; font-weight: 800; }
.floor-name { font-size: 13px; font-weight: 700; }
.floor-best { font-size: 11px; opacity: .7; }
.floor-stars { font-size: 13px; letter-spacing: 1px; }

/* Leaderboard */
.lb-host { margin-top: 6px; }
.lb-table { width: 100%; border-collapse: collapse; }
.lb-table th, .lb-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--mid); }
.lb-table th { color: var(--light); font-size: 13px; }
.lb-table td:last-child, .lb-table th:last-child { text-align: right; }
.status { color: var(--light); text-align: center; padding: 12px; }

/* Settings */
.settings { display: flex; flex-direction: column; gap: 16px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.set-label { font-weight: 700; }
.set-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-btn {
  appearance: none; border: 3px solid #5a1010; background: #b23a3a; color: #fff;
  border-radius: var(--radius); padding: 12px; font: inherit; font-weight: 700; cursor: pointer; margin-top: 10px;
}

/* ---------------- Game screen ---------------- */
#hud {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 8px calc(10px + var(--safe-l));
  background: var(--dark);
  border-bottom: 2px solid var(--mid);
}
.hud-btn {
  appearance: none; border: 2px solid var(--light); background: transparent; color: var(--pale);
  width: 40px; height: 40px; border-radius: 8px; font-size: 22px; cursor: pointer; flex: none;
}
.hud-stats { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.hud-title { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-metrics { display: flex; gap: 14px; font-size: 13px; color: var(--light); }

#board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--dark);
  touch-action: none;
}
#board { width: 100%; height: 100%; display: block; image-rendering: pixelated; }

#controls {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px calc(16px + var(--safe-r)) calc(14px + var(--safe-b)) calc(16px + var(--safe-l));
  background: var(--dark);
  border-top: 2px solid var(--mid);
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, var(--d-size));
  grid-template-rows: repeat(3, var(--d-size));
  gap: 6px;
}
.dbtn {
  appearance: none; border: 3px solid var(--dark); background: var(--light); color: var(--ink);
  border-radius: 12px; font-size: 22px; font-weight: 800; cursor: pointer; box-shadow: 0 4px 0 var(--mid);
  display: flex; align-items: center; justify-content: center;
}
.dbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--mid); }
.dbtn.up { grid-area: 1 / 2; }
.dbtn.left { grid-area: 2 / 1; }
.dbtn.switch { grid-area: 2 / 2; background: var(--mid); color: var(--pale); font-size: 20px; }
.dbtn.right { grid-area: 2 / 3; }
.dbtn.down { grid-area: 3 / 2; }

.actions { display: flex; flex-direction: column; gap: 10px; }
.act-btn {
  appearance: none; border: 3px solid var(--dark); background: var(--light); color: var(--ink);
  width: var(--d-size); height: var(--d-size); border-radius: 12px; font-size: 26px; cursor: pointer;
  box-shadow: 0 4px 0 var(--mid);
}
.act-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--mid); }

/* ---------------- Overlay ---------------- */
#overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 56, 15, .82);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.panel {
  background: var(--dark);
  border: 3px solid var(--light);
  border-radius: 16px;
  padding: 24px;
  max-width: 420px; width: 100%;
  text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}
.win-title { margin: 0; font-size: 28px; color: var(--pale); }
.panel p { margin: 0; color: var(--light); }
.panel-btns { display: flex; flex-direction: column; gap: 10px; }
.bonus-pop { font-size: 30px; font-weight: 800; color: var(--pale); }
.win-stars { font-size: 34px; letter-spacing: 6px; color: var(--pale) !important; line-height: 1; }
.win-perfect { font-weight: 800; color: var(--pale) !important; }
.big-score { font-size: 20px; font-weight: 800; color: var(--pale); }
.name-input {
  font: inherit; font-size: 18px; padding: 12px; border-radius: 10px;
  border: 3px solid var(--light); background: var(--pale); color: var(--ink); text-align: center;
}

/* ---------------- Larger / landscape screens ---------------- */
@media (min-width: 720px) and (orientation: landscape) {
  :root { --d-size: 56px; }
  #controls { padding-left: 8vw; padding-right: 8vw; }
}
@media (min-height: 760px) {
  :root { --d-size: 68px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  :root { --d-size: 46px; }
  .logo { font-size: 44px; }
  .title-hero { margin: 3vh 0; }
}
