:root {
  color-scheme: light;
  --ink: #24312e;
  --paper: #f2eedf;
  --paper-dark: #ded6c0;
  --moss: #687b58;
  --gold: #c99a43;
  --red: #934f45;
  font-family: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #cbd6c7;
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }

#game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(#bacbd0, #e8e2cc 68%, #c8cfb5);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.hud {
  position: fixed;
  z-index: 10;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  height: 64px;
  display: flex;
  align-items: stretch;
  gap: 10px;
  pointer-events: none;
}

.brand, .stats, .next-card, .icon-button, .menu {
  border: 1px solid rgba(54, 61, 49, .34);
  background: rgba(242, 238, 223, .91);
  box-shadow: 0 4px 18px rgba(49, 56, 50, .15), inset 0 1px rgba(255,255,255,.7);
  backdrop-filter: blur(8px);
}

.brand {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px 8px 10px;
  color: var(--ink);
  text-decoration: none;
  border-radius: 7px 2px 7px 2px;
}

.brand-crown { font-size: 28px; color: var(--red); line-height: 1; }
.brand b, .brand small { display: block; letter-spacing: .12em; line-height: 1; }
.brand b { font-size: 15px; }
.brand small { margin-top: 5px; font-size: 8px; }

.stats { display: flex; border-radius: 3px 8px 3px 8px; }
.stat { min-width: 76px; padding: 9px 13px; text-align: center; }
.stat + .stat { border-left: 1px solid rgba(54, 61, 49, .22); }
.stat small, .next-card small { display: block; font: 700 9px/1 Arial, sans-serif; letter-spacing: .16em; opacity: .62; }
.stat strong { display: block; margin-top: 7px; font: 700 22px/1 Georgia, serif; }

.next-card {
  margin-left: auto;
  min-width: 83px;
  display: grid;
  grid-template-columns: auto 48px;
  align-items: center;
  gap: 4px;
  padding: 7px 8px 7px 12px;
  border-radius: 8px 3px 8px 3px;
}
.next-card img { width: 48px; height: 48px; object-fit: contain; }

.icon-button {
  pointer-events: auto;
  width: 48px;
  border-radius: 4px 9px 4px 9px;
  font: 800 18px/1 Arial, sans-serif;
  letter-spacing: 2px;
  cursor: pointer;
}

.menu {
  position: fixed;
  z-index: 30;
  top: calc(max(12px, env(safe-area-inset-top)) + 72px);
  right: max(12px, env(safe-area-inset-right));
  width: 190px;
  padding: 8px;
  border-radius: 4px 10px 4px 10px;
}
.menu button { width: 100%; padding: 11px; border: 0; border-bottom: 1px solid rgba(36,49,46,.15); background: transparent; text-align: left; cursor: pointer; }
.menu button:last-child { border-bottom: 0; opacity: .65; }

.controls {
  position: fixed;
  z-index: 12;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: stretch;
  padding: 7px;
  border: 1px solid rgba(54, 61, 49, .30);
  border-radius: 10px 4px 10px 4px;
  background: rgba(242, 238, 223, .90);
  box-shadow: 0 7px 25px rgba(45, 51, 46, .19), inset 0 1px rgba(255,255,255,.7);
  backdrop-filter: blur(8px);
}

.controls button {
  min-width: 104px;
  min-height: 48px;
  padding: 7px 14px;
  border: 1px solid rgba(48, 61, 54, .32);
  border-radius: 7px 2px 7px 2px;
  background: #e6e0cd;
  font: 700 13px/1 Arial, sans-serif;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: inset 0 1px rgba(255,255,255,.7), 0 2px 0 rgba(48,61,54,.18);
}
.controls button span { margin-right: 5px; font-size: 20px; vertical-align: -2px; }
.controls button:active { transform: translateY(2px); box-shadow: inset 0 1px rgba(255,255,255,.5); }
.controls .drop-button { background: var(--moss); color: white; border-color: #4f6142; }
.controls button b { display: inline-grid; place-items: center; margin-left: 4px; width: 20px; height: 20px; border-radius: 50%; background: rgba(36,49,46,.13); }
.controls .small-control { display: none; min-width: 45px; padding: 0; font-size: 28px; }

.hint, .toast {
  position: fixed;
  z-index: 9;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 13px;
  border-radius: 20px;
  background: rgba(42, 54, 49, .77);
  color: #f6f0dd;
  text-align: center;
  pointer-events: none;
}
.hint { bottom: 84px; font-size: 12px; transition: opacity .5s; }
.hint.gone { opacity: 0; }
.toast { top: 88px; opacity: 0; font-size: 13px; transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 5px); }

.lava-status {
  position: fixed;
  z-index: 9;
  top: 88px;
  right: max(12px, env(safe-area-inset-right));
  min-width: 116px;
  padding: 7px 11px;
  border: 1px solid rgba(79, 55, 50, .32);
  border-radius: 7px 2px 7px 2px;
  background: rgba(116, 82, 73, .84);
  color: #f1e9d7;
  text-align: right;
  box-shadow: 0 4px 14px rgba(55, 42, 39, .15);
  pointer-events: none;
  transition: background .25s, transform .25s;
}
.lava-status small { display: block; font: 700 7px/1 Arial, sans-serif; letter-spacing: .13em; opacity: .76; }
.lava-status strong { display: block; margin-top: 4px; font: 700 17px/1 Georgia, serif; }
.lava-status.danger { background: rgba(125, 66, 55, .94); transform: translateY(3px); }

@media (max-width: 700px) {
  .hud {
    height: 54px;
    gap: 6px;
    display: grid;
    grid-template-columns: 86px minmax(104px, 1fr) 48px 38px;
  }
  .brand { padding: 6px 8px; }
  .brand-crown { font-size: 22px; }
  .brand b { font-size: 12px; }
  .brand small { font-size: 7px; margin-top: 3px; }
  .stats { min-width: 0; }
  .stat { min-width: 0; flex: 1; padding: 7px 6px; }
  .stat strong { font-size: 17px; margin-top: 5px; }
  .next-card { margin-left: 0; min-width: 0; grid-template-columns: 1fr; padding: 3px; }
  .next-card small { display: none; }
  .next-card img { width: 46px; height: 46px; }
  .icon-button { width: 38px; }
  .controls {
    width: calc(100% - 14px);
    bottom: max(7px, env(safe-area-inset-bottom));
    gap: 4px;
    padding: 5px;
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 36px;
  }
  .controls button { flex: 1; min-width: 0; min-height: 52px; padding: 6px 5px; font-size: 11px; }
  .controls button span { display: block; margin: 0 0 3px; font-size: 18px; }
  .controls .small-control { display: block; width: 36px; min-width: 0; padding: 0; font-size: 25px; }
  .controls .small-control span { display: inline; }
  .hint { bottom: 76px; width: max-content; max-width: 88%; font-size: 10px; }
  .toast { top: 75px; }
  .lava-status { top: 75px; right: 8px; min-width: 102px; padding: 6px 8px; }
  .lava-status strong { font-size: 15px; }
}

@media (max-width: 390px) {
  .hud { grid-template-columns: 77px minmax(100px, 1fr) 44px 36px; }
  .brand-crown { display: none; }
  .brand { padding: 7px; }
  .brand b { font-size: 11px; }
  .next-card img { width: 40px; height: 44px; }
  .icon-button { width: 36px; }
  .stat small { font-size: 7px; }
  .stat strong { font-size: 15px; }
  .controls button b { width: 17px; height: 17px; }
}

[hidden] { display: none !important; }
