:root {
  color-scheme: light;
  --ink: #151821;
  --paper: #fff9e8;
  --paper-strong: #fff3c6;
  --grape: #5e2d8f;
  --grape-dark: #32164f;
  --peach: #ff8c91;
  --leaf: #3da65e;
  --gold: #f8cb30;
  --wood: #8a542c;
  --danger: #34313a;
  --shadow: 0 18px 38px rgba(23, 18, 33, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, #43236f 0%, #245b88 36%, #5d7f41 68%, #8a542c 100%);
  color: var(--ink);
  font-family:
    "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  position: relative;
  width: min(100vw, 520px);
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: #8fd7ee;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: start;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    8px
    max(10px, env(safe-area-inset-left));
  pointer-events: none;
}

.brand,
.meters,
.recipe-card,
.overlay-panel,
.icon-button {
  border: 1px solid rgba(255, 255, 255, 0.56);
  background: rgba(255, 249, 232, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
}

.brand p,
.brand h1,
.meters,
.meters dt,
.meters dd,
.recipe-card,
.overlay p,
.overlay h2 {
  margin: 0;
}

.brand p {
  color: var(--grape);
  font-size: clamp(0.64rem, 2.4vw, 0.76rem);
  font-weight: 900;
  line-height: 1.05;
}

.brand h1 {
  margin-top: 2px;
  color: var(--ink);
  font-size: clamp(0.86rem, 3.2vw, 1.12rem);
  font-weight: 900;
  line-height: 1.05;
  overflow-wrap: normal;
  white-space: nowrap;
  word-break: keep-all;
}

.meters {
  display: grid;
  grid-template-columns: repeat(3, minmax(42px, 1fr));
  gap: 1px;
  min-width: min(45vw, 196px);
  overflow: hidden;
  border-radius: 8px;
}

.meters div {
  display: grid;
  gap: 1px;
  min-width: 0;
  padding: 8px 7px;
  text-align: center;
}

.meters dt {
  color: #684127;
  font-size: clamp(0.62rem, 2.3vw, 0.72rem);
  font-weight: 900;
  line-height: 1;
}

.meters dd {
  min-width: 0;
  color: var(--ink);
  font-size: clamp(0.98rem, 4.1vw, 1.32rem);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 1.05;
}

.recipe-card {
  grid-column: 1 / 3;
  display: flex;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
}

.recipe-card span {
  flex: 0 0 auto;
  color: var(--grape);
  font-size: clamp(0.7rem, 2.6vw, 0.8rem);
  font-weight: 900;
}

.recipe-card strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(0.74rem, 2.8vw, 0.9rem);
  font-weight: 900;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border-radius: 8px;
  color: var(--grape-dark);
  cursor: pointer;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
  pointer-events: auto;
  touch-action: manipulation;
}

.icon-button:active {
  transform: translateY(2px);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: end center;
  padding:
    18px
    max(18px, env(safe-area-inset-right))
    max(30px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background:
    linear-gradient(180deg, rgba(24, 12, 36, 0.05), rgba(24, 12, 36, 0.38)),
    radial-gradient(circle at 52% 72%, rgba(248, 203, 48, 0.34), transparent 40%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-panel {
  width: min(100%, 420px);
  padding: 18px;
  border-radius: 8px;
  text-align: center;
}

.kicker {
  color: var(--grape);
  font-size: clamp(0.82rem, 3.2vw, 1rem);
  font-weight: 900;
}

.overlay h2 {
  margin-top: 6px;
  color: var(--ink);
  font-size: clamp(1.35rem, 6vw, 2rem);
  font-weight: 900;
  line-height: 1.1;
}

.overlay-score {
  margin-top: 8px;
  color: #5a3824;
  font-size: clamp(0.9rem, 3.5vw, 1.08rem);
  font-weight: 900;
}

.primary-button {
  display: inline-grid;
  min-width: min(100%, 210px);
  min-height: 52px;
  margin-top: 16px;
  padding: 12px 22px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffe36a, #f8a729);
  box-shadow:
    0 8px 0 #8a542c,
    0 18px 28px rgba(55, 31, 12, 0.28);
  color: #17130d;
  cursor: pointer;
  font: inherit;
  font-size: clamp(1.08rem, 4.6vw, 1.28rem);
  font-weight: 900;
  line-height: 1;
  touch-action: manipulation;
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow:
    0 4px 0 #8a542c,
    0 10px 18px rgba(55, 31, 12, 0.26);
}

@media (max-width: 390px) {
  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .brand {
    grid-column: 1 / 2;
  }

  .meters {
    grid-column: 1 / 3;
    grid-row: 2;
    justify-self: stretch;
  }

  .recipe-card {
    grid-column: 1 / 3;
    grid-row: 3;
  }

  .icon-button {
    grid-column: 2;
    grid-row: 1;
  }
}

@media (min-width: 760px) {
  .game-shell {
    border-right: 1px solid rgba(255, 255, 255, 0.3);
    border-left: 1px solid rgba(255, 255, 255, 0.3);
  }
}
