:root {
  --bg: #020203;
  --panel: #101014;
  --panel-2: #1a1a20;
  --text: #fff8eb;
  --muted: rgba(255, 248, 235, 0.62);
  --line: rgba(255, 255, 255, 0.1);
  --accent: #d7b46a;
  --danger: #ff7670;
  --good: #8ee39f;
}

* { box-sizing: border-box; }
* {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input {
  -webkit-user-select: text;
  user-select: text;
}
html, body { min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

button, input { font: inherit; }

button, input {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 18px;
}

button {
  min-height: 48px;
  padding: 0.75rem 1rem;
  font-weight: 900;
  touch-action: manipulation;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:active { transform: scale(0.985); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  position: relative;
  width: min(820px, 100%);
  height: 100svh;
  margin: 0 auto;
  padding: max(0.2rem, env(safe-area-inset-top)) max(0.2rem, env(safe-area-inset-right)) max(0.2rem, env(safe-area-inset-bottom)) max(0.2rem, env(safe-area-inset-left));
  background: #020203;
}

.players {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 0.22rem;
  height: 100%;
}

.player {
  position: relative;
  display: grid;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(135deg, #172f3d, #061318 66%, #020304);
  border-radius: 16px;
}

.player[data-player="1"] { background: linear-gradient(135deg, #432418, #140807 68%, #030303); }
.opponent { transform: rotate(180deg); }

.lifeRow {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

.life {
  position: relative;
  z-index: 1;
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: clamp(8rem, 42vw, 17rem);
  font-weight: 1000;
  line-height: 0.78;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.09em;
  text-shadow: 0 6px 28px rgba(0, 0, 0, 0.32);
  pointer-events: none;
}

.life.needsUnderline {
  text-decoration: underline;
  text-decoration-thickness: 0.055em;
  text-underline-offset: 0.13em;
}

.life.deathPhrase {
  padding-inline: 0.25rem;
  font-size: clamp(2.8rem, 16vw, 7rem);
  letter-spacing: -0.04em;
  text-align: center;
  overflow-wrap: anywhere;
}

.step {
  position: relative;
  z-index: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  height: 100%;
  min-height: 0;
  padding: 0 clamp(0.75rem, 5vw, 2rem);
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.14);
  font-size: clamp(3.4rem, 14vw, 6rem);
  border-radius: 14px;
}

.stepDown { grid-column: 1; justify-content: flex-start; }
.stepUp { grid-column: 2; justify-content: flex-end; }

.stepDown:active { background: rgba(255, 118, 112, 0.11); color: var(--danger); }
.stepUp:active { background: rgba(142, 227, 159, 0.11); color: var(--good); }

.burst {
  position: absolute;
  left: 50%;
  bottom: 10%;
  z-index: 2;
  min-width: 4.8rem;
  padding: 0.35rem 0.8rem;
  opacity: 0;
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  text-align: center;
  font-size: clamp(1.35rem, 8vw, 2.8rem);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%) translateY(0.4rem) scale(0.96);
  transition: opacity 120ms linear, transform 120ms linear;
  pointer-events: none;
}

.burst.show { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
.burst.positive { color: var(--good); }
.burst.negative { color: var(--danger); }

.menuButton {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 5;
  width: 64px;
  height: 64px;
  min-height: 64px;
  padding: 0;
  background: rgba(3, 3, 4, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(12px);
  color: rgba(255, 248, 235, 0.86);
  font-size: 1.55rem;
  transform: translate(-50%, -50%);
}

.menuButton:active { transform: translate(-50%, -50%) scale(0.96); }

.timerBadge {
  position: absolute;
  left: 50%;
  bottom: 0.55rem;
  z-index: 3;
  min-height: 38px;
  padding: 0.3rem 0.75rem;
  background: rgba(3, 3, 4, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: var(--accent);
  font-size: clamp(1rem, 4.5vw, 1.35rem);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.timerBadge.paused { color: var(--muted); }

.drawer {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 6;
  width: min(28rem, calc(100% - 1.1rem));
  max-height: min(82svh, 44rem);
  padding: 1rem;
  overflow: auto;
  background: rgba(12, 12, 15, 0.97);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.7);
  transform: translate(-50%, -50%);
}

.drawer[hidden] { display: none; }
.compactDrawer { width: min(23rem, calc(100% - 1.1rem)); }

.sectionTitle, .optionHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

h1, h2 { margin: 0; line-height: 1; }
h1 { font-size: 1.35rem; }
h2 { color: var(--muted); font-size: 0.82rem; font-weight: 950; letter-spacing: 0.08em; text-transform: uppercase; }

.ghost { background: transparent; }
.optionBlock { display: grid; gap: 0.65rem; margin-top: 1rem; }

.primaryGrid, .timerActions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.addTimeGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  margin-top: 0.65rem;
}

.bigTimer {
  display: block;
  margin: 0.8rem 0;
  color: var(--accent);
  text-align: center;
  font-size: clamp(3rem, 18vw, 5rem);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timerActions { width: 9.2rem; }
.primaryGrid button, .full { min-height: 58px; }
.reset { background: #251e10; border-color: #564018; color: var(--accent); }

.customTime {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.customTime input {
  min-height: 54px;
  padding: 0.75rem 0.9rem;
}

.full { width: 100%; }
.timerStatus { margin: 0; color: var(--muted); font-weight: 800; text-align: center; }

.history {
  display: grid;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.6rem;
  padding: 0.65rem 0.7rem;
  background: #08080a;
  border: 1px solid #202027;
  border-radius: 14px;
}

.history .meta { color: var(--muted); font-size: 0.82rem; }
.history .delta { font-weight: 950; font-variant-numeric: tabular-nums; }
.history .positive { color: var(--good); }
.history .negative { color: var(--danger); }
.empty { color: var(--muted); text-align: center; padding: 1rem 0; }

@media (orientation: landscape) and (max-height: 560px) {
  .app { max-width: none; }
  .players { grid-template-rows: none; grid-template-columns: 1fr 1fr; }
  .opponent { transform: none; }
  .life { font-size: clamp(5rem, 18vw, 11rem); }
}

@media (max-width: 420px) {
  .life { font-size: clamp(7.5rem, 43vw, 12.5rem); }
  .menuButton { width: 58px; height: 58px; min-height: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
  button:active { transform: none; }
  .menuButton, .menuButton:active { transform: translate(-50%, -50%); }
}
