:root {
  --ink: #24180f;
  --paper: #fff8ee;
  --wood: #8a5528;
  --wood-dark: #5c3818;
  --sky: #7ec8ef;
  --leaf: #2f7a3d;
  --you: #128f86;
  --rival: #d4532a;
  --gold: #e7a31a;
  --line: rgba(36, 24, 15, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
}

body {
  font-family: "Segoe UI", "Trebuchet MS", "Gill Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, #fff4c8 0 8%, transparent 26%),
    linear-gradient(#6eb8e4 0%, #d7f2ff 46%, #4e9a55 46%, #2d6d38 100%);
  overflow: hidden;
}

button, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 2px solid var(--wood-dark);
  background: linear-gradient(#fffdf8, #f3e2c4);
  border-radius: 12px;
  padding: 0.55rem 0.9rem;
  box-shadow: 0 2px 0 #c9a06a;
}

button:hover:not(:disabled) { filter: brightness(1.04); }

button:active:not(:disabled) { transform: translateY(1px); }

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.35);
  opacity: 0.55;
}

button:focus-visible, select:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px 14px;
}

.card {
  width: min(720px, 100%);
  background: rgba(255, 248, 238, 0.94);
  border: 4px solid var(--wood);
  border-radius: 22px;
  padding: 28px 26px 22px;
  box-shadow: 0 18px 50px rgba(40, 24, 8, 0.25);
}

.eyebrow {
  margin: 0 0 6px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.74rem;
  color: #7a4b22;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 8px 0 0;
  font-size: 1.12rem;
  color: #5c4632;
}

.menu-actions, .end-actions, .dup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-top: 18px;
}

.play-btn, .end-actions button, #retryBtn {
  background: linear-gradient(#1aa89a, #0e7f78);
  color: white;
  border-color: #0b534c;
  font-weight: 700;
  min-height: 46px;
}

.ghost {
  background: transparent;
}

.lang-field {
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 700;
}

select {
  border: 2px solid var(--wood);
  border-radius: 10px;
  background: white;
  padding: 0.45rem 0.6rem;
  min-height: 42px;
}

.how {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 2px dashed rgba(138, 85, 40, 0.35);
}

.how h2 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.how p, #duplicateBody, #endBody {
  margin: 0;
  line-height: 1.45;
}

#match {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(#8ecff0, #e7f7ff 30%, #5aa35c);
}

.topbar, .status-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 0;
}

.brand { min-width: 0; }

.brand h1 {
  font-size: clamp(1rem, 2vw, 1.35rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  margin: 0;
  color: #3d342b;
  font-size: 0.86rem;
}

.top-actions { display: flex; gap: 8px; align-items: end; }

#muteBtn, #menuBtn { min-height: 42px; }

.hp-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 8px 12px 0;
}

.hp-meta {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.hp-track {
  position: relative;
  height: 22px;
  border-radius: 999px;
  background: #1d2430;
  border: 2px solid #fff6;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35);
}

.hp-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.hp-track > div {
  height: 100%;
  width: 100%;
  border-radius: inherit;
}

.you-label { color: #0c615c; }
.rival-label { color: #9d3416; margin-left: auto; }

.status-row { padding-top: 6px; padding-bottom: 4px; }

#status { margin: 0; font-weight: 800; }

#hint {
  margin: 2px 0 0;
  color: #3f342b;
  font-size: 0.9rem;
}

#windReadout {
  font-weight: 800;
  background: rgba(255, 248, 238, 0.8);
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}

#meter {
  height: 10px;
  margin: 0 12px 4px;
  border-radius: 999px;
  background: rgba(20, 24, 28, 0.2);
  overflow: hidden;
}

#meterFill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f0d15a, #ef7a2a 70%, #ffef9a);
}

#stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
}

#frame {
  position: relative;
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(20, 40, 20, 0.25);
  background: #8fd0f2;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 14px;
  touch-action: none;
  cursor: crosshair;
}

#endCard {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(12, 28, 40, 0.42);
  border-radius: 14px;
  padding: 12px;
}

#endCard .card { width: min(460px, 100%); }

#dock {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  padding: 6px 10px 10px;
}

.power {
  text-align: left;
  padding: 6px 8px 7px;
  min-height: 64px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 1px 6px;
  background: rgba(255, 248, 238, 0.92);
}

.power-name {
  font-weight: 800;
  font-size: 0.78rem;
  line-height: 1.15;
}

.power-count {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 0.78rem;
  color: #6b4a22;
}

.power-desc {
  grid-column: 1 / -1;
  font-size: 0.68rem;
  line-height: 1.2;
  color: #5c4a3b;
}

.power.armed {
  border-color: #a56b00;
  box-shadow: inset 0 0 0 2px var(--gold);
  background: #fff4cc;
}

.power.live {
  box-shadow: inset 0 0 0 2px #7ecbff;
}

#p-double { border-top: 4px solid #1a9b8e; }
#p-powerThrow { border-top: 4px solid #e23d3d; }
#p-stinky { border-top: 4px solid #6aaf32; }
#p-powerUp { border-top: 4px solid #e7a31a; }
#p-shield { border-top: 4px solid #3aa0d8; }
#p-gravity { border-top: 4px solid #3d4ec7; }
#p-split { border-top: 4px solid #c45ad4; }

@media (max-width: 980px) {
  #dock {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: auto;
    max-height: 168px;
  }
  .power-desc { display: none; }
  .hp-track { height: 16px; }
}

@media (max-width: 640px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .brand h1 { white-space: normal; }
  #dock { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-row { align-items: flex-start; flex-direction: column; }
}
