/* Kananeko's palette (src/game/palette.ts) */
:root {
  --paper: #fff4e0;
  --latte: #f2dcc0;
  --cocoa: #b98a78;
  --ink: #4b2d3c;
  --sakura: #f093a8;
  --sakura-light: #ffd9e0;
  --ginger: #f0a060;
  --ginger-light: #ffdcae;
  --sky: #d8ecf8;
  --radius: 14px;
  --shadow: 4px 4px 0 var(--cocoa);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* No double-tap zoom (play.ts also cancels quick second taps, which iOS zooms on anyway) */
  touch-action: manipulation;
}

body {
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--paper);
  color: var(--ink);
  font-family:
    ui-rounded, 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'Noto Sans JP', system-ui, sans-serif;
  line-height: 1.55;
  /* No double-tap zoom anywhere; the game controls opt out of all panning too */
  touch-action: manipulation;
}

a {
  color: var(--ink);
  text-decoration-color: var(--sakura);
  text-decoration-thickness: 2px;
}

.hero,
main,
footer {
  max-width: 560px;
  margin: 0 auto;
}

.hero {
  text-align: center;
}

h1 {
  margin: 8px 0 4px;
  font-size: clamp(2rem, 9vw, 3rem);
  letter-spacing: 0.04em;
  color: var(--ginger);
  text-shadow:
    2px 2px 0 var(--ink),
    -1px -1px 0 var(--ink),
    1px -1px 0 var(--ink),
    -1px 1px 0 var(--ink);
}

h1 .romaji {
  display: block;
  font-size: 0.4em;
  letter-spacing: 0.3em;
  color: var(--ink);
  text-shadow: none;
}

h2 {
  margin-top: 0;
  font-size: 1.2rem;
}

/* ---------------------------------------------------------------- the console */

.console {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  margin: 20px auto;
  padding: 16px;
  max-width: 420px;
  background: var(--latte);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.screen {
  position: relative;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
  aspect-ratio: 160 / 144;
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.start {
  position: absolute;
  inset: 0;
  margin: auto;
  width: max-content;
  height: max-content;
  padding: 12px 28px;
  font: inherit;
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--ink);
  background: var(--sakura-light);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.start:disabled {
  opacity: 0.6;
  cursor: progress;
}

.status {
  min-height: 1.5em;
  margin: 6px 0 0;
  text-align: center;
  font-size: 0.9rem;
}

.status:empty {
  display: none;
}

/* ---------------------------------------------------------------- controls */

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    'dpad ab'
    'pills pills';
  align-items: center;
  gap: 12px 8px;
  margin-top: 16px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.controls button {
  font: inherit;
  color: var(--ink);
  border: 3px solid var(--ink);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.dpad {
  grid-area: dpad;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  grid-template-areas:
    '. up .'
    'left hub right'
    '. down .';
  touch-action: none;
}

.dpad .arm,
.dpad .hub {
  background: var(--ink);
}

.dpad .up {
  grid-area: up;
  border-radius: 8px 8px 0 0;
}

.dpad .down {
  grid-area: down;
  border-radius: 0 0 8px 8px;
}

.dpad .left {
  grid-area: left;
  border-radius: 8px 0 0 8px;
}

.dpad .right {
  grid-area: right;
  border-radius: 0 8px 8px 0;
}

.dpad .hub {
  grid-area: hub;
}

.dpad[data-held~='up'] .up,
.dpad[data-held~='down'] .down,
.dpad[data-held~='left'] .left,
.dpad[data-held~='right'] .right {
  background: var(--sakura);
}

.ab {
  grid-area: ab;
  justify-self: center;
  display: flex;
  gap: 14px;
  /* B sits lower-left of A, like the real thing */
  transform: rotate(-20deg);
}

.round {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 1.3rem;
  font-weight: bold;
  background: var(--sakura);
  box-shadow: 3px 3px 0 var(--cocoa);
}

.round.b {
  margin-top: 28px;
}

.pills {
  grid-area: pills;
  display: flex;
  justify-content: center;
  gap: 18px;
}

.pill {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: bold;
  letter-spacing: 0.08em;
  background: var(--paper);
  box-shadow: 2px 2px 0 var(--cocoa);
}

.round.pressed,
.pill.pressed {
  transform: translate(2px, 2px);
  box-shadow: none;
  background: var(--sakura-light);
}

.toolbar {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

.toggle {
  font: inherit;
  font-size: 0.9rem;
  padding: 4px 14px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- content */

.card {
  margin: 24px 0;
  padding: 18px 20px;
  background: #fffaf0;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.keys {
  border-collapse: collapse;
  margin: 8px 0;
}

.keys th {
  text-align: left;
  padding: 4px 16px 4px 0;
  font-size: 0.9rem;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  margin: 0 2px;
  padding: 0 6px;
  text-align: center;
  font: inherit;
  font-size: 0.85rem;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 1px 1px 0 var(--cocoa);
}

.hint {
  font-size: 0.85rem;
  opacity: 0.8;
}

.shots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.shots img {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border: 2px solid var(--ink);
  border-radius: 8px;
}

footer {
  font-size: 0.8rem;
  text-align: center;
  opacity: 0.85;
}

/* ---------------------------------------------------------------- side by side */

/* Phones in portrait: once playing, the screen and controls get the whole view */
@media (max-width: 600px) {
  body.playing .hero {
    display: none;
  }

  body.playing .console {
    margin-top: 0;
  }
}

/* Wide screens: the same handheld layout, so the whole console fits the window */
@media (min-width: 860px) {
  main {
    max-width: 860px;
  }

  .card {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
  }

  .screen {
    height: min(58vh, 432px);
  }
}

@media (orientation: landscape) and (max-height: 540px), (min-width: 860px) {
  .console {
    max-width: none;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
      'dpad screen ab'
      'dpad status ab'
      'pills pills pills'
      'toolbar toolbar toolbar';
    align-items: center;
    margin: 0 auto;
  }

  .screen {
    grid-area: screen;
  }

  .status {
    grid-area: status;
  }

  .controls {
    display: contents;
  }

  .toolbar {
    grid-area: toolbar;
    margin-top: 6px;
  }
}

/* Phones in landscape: just the game, filling the height, controls either side */
@media (orientation: landscape) and (max-height: 540px) {
  body.playing {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  body.playing .hero,
  body.playing .card,
  body.playing footer {
    display: none;
  }

  main {
    max-width: none;
  }

  .console {
    padding: 10px 16px;
    gap: 0 16px;
    grid-template-areas:
      'dpad screen ab'
      'pills screen toolbar';
  }

  .screen {
    grid-row: 1 / span 2;
    height: calc(100vh - 56px);
    height: calc(100svh - 56px);
    max-height: 432px;
  }

  .status {
    grid-area: toolbar;
  }

  .dpad {
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
  }

  .pills {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }
}
