:root {
  color-scheme: light;
  --bg: #edf2ee;
  --paper: #fffdf8;
  --ink: #17201c;
  --muted: #66756d;
  --line: rgba(23, 32, 28, 0.14);
  --table: #0f6e56;
  --table-deep: #0a4f43;
  --table-edge: #f2d37d;
  --panel: rgba(255, 255, 255, 0.9);
  --card: #fffaf0;
  --red: #c7373d;
  --black: #202622;
  --blue: #2d5fba;
  --blue-dark: #224b94;
  --amber: #f3bd4f;
  --good: #138554;
  --bad: #b8343a;
  --shadow: rgba(27, 43, 37, 0.22);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(15, 110, 86, 0.16), transparent 34%),
    linear-gradient(300deg, rgba(243, 189, 79, 0.18), transparent 38%),
    linear-gradient(180deg, #f8faf7 0%, var(--bg) 100%);
}

button {
  font: inherit;
}

.app {
  display: flex;
  flex-direction: column;
  width: min(1280px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(18px, 3vh, 30px) 0 clamp(18px, 3vh, 34px);
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: clamp(12px, 2vh, 20px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--table-deep);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 58px;
  line-height: 0.95;
  letter-spacing: 0;
}

.lede {
  max-width: 520px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.45;
}

.scoreboard {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
}

.scoreboard span {
  min-width: 108px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  text-align: center;
  box-shadow: 0 8px 22px rgba(27, 43, 37, 0.08);
}

.scoreboard strong {
  color: var(--ink);
}

.game {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 270px);
  gap: clamp(14px, 2vw, 18px);
  align-items: stretch;
  min-height: 0;
}

.table {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto auto auto auto;
  align-content: center;
  gap: clamp(10px, 1.7vh, 16px);
  min-height: 0;
  padding: clamp(16px, 2.8vh, 28px);
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.18), transparent 42%),
    linear-gradient(145deg, var(--table), var(--table-deep));
  background-size:
    26px 26px,
    26px 26px,
    auto,
    auto;
  box-shadow:
    0 28px 68px var(--shadow),
    inset 0 0 0 3px rgba(242, 211, 125, 0.18);
}

.target {
  justify-self: center;
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  border: 2px solid rgba(255, 255, 255, 0.56);
  border-radius: 50%;
  color: white;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent),
    rgba(6, 56, 47, 0.62);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.24),
    inset 0 0 0 1px rgba(242, 211, 125, 0.24);
}

.target span {
  color: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.target strong {
  margin-top: -8px;
  font-size: 48px;
  line-height: 1;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(86px, 136px));
  gap: clamp(10px, 1.8vw, 16px);
  justify-content: center;
  min-height: 176px;
}

.card {
  position: relative;
  display: grid;
  align-content: space-between;
  min-height: 176px;
  padding: 12px;
  border: 0;
  border-radius: 8px;
  color: var(--black);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 246, 222, 0.78)),
    var(--card);
  box-shadow:
    0 16px 24px rgba(0, 0, 0, 0.2),
    0 2px 0 rgba(255, 255, 255, 0.65) inset,
    inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    opacity 150ms ease;
}

.card:hover:not(:disabled),
.card:focus-visible {
  transform: translateY(-9px);
  box-shadow:
    0 24px 36px rgba(0, 0, 0, 0.25),
    0 2px 0 rgba(255, 255, 255, 0.7) inset,
    inset 0 0 0 2px rgba(242, 211, 125, 0.66);
  outline: none;
}

.card:disabled {
  cursor: default;
  opacity: 0.42;
  transform: translateY(10px) scale(0.96);
}

.card.red {
  color: var(--red);
}

.card-corner {
  display: grid;
  justify-items: start;
  gap: 2px;
  font-weight: 900;
}

.card-corner.bottom {
  justify-self: end;
  rotate: 180deg;
}

.rank {
  font-size: 25px;
  line-height: 1;
}

.suit {
  font-size: 22px;
  line-height: 1;
}

.card-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 58px;
  font-weight: 900;
  pointer-events: none;
}

.expression-wrap {
  display: grid;
  gap: 7px;
}

.expression-label {
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.expression {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 56px;
  padding: 9px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: rgba(4, 42, 36, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.placeholder {
  color: rgba(255, 255, 255, 0.62);
  font-weight: 700;
}

.token {
  min-width: 38px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: white;
  font-weight: 900;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.16);
  cursor: pointer;
}

.token.operator-token,
.token.paren-token {
  color: white;
  background: #20334b;
}

.keypad,
.actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
}

.key,
.icon-btn,
.text-btn,
.primary-btn {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 130ms ease,
    filter 130ms ease,
    opacity 130ms ease,
    box-shadow 130ms ease;
}

.key:hover:not(:disabled),
.icon-btn:hover:not(:disabled),
.text-btn:hover:not(:disabled),
.primary-btn:hover:not(:disabled),
.key:focus-visible,
.icon-btn:focus-visible,
.text-btn:focus-visible,
.primary-btn:focus-visible {
  transform: translateY(-2px);
  outline: none;
  filter: brightness(1.04);
}

.key:disabled,
.icon-btn:disabled,
.text-btn:disabled,
.primary-btn:disabled {
  cursor: default;
  opacity: 0.42;
}

.key {
  width: 54px;
  color: white;
  background: #20334b;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
}

.operator {
  background: var(--blue);
}

.paren {
  background: #5d5040;
}

.icon-btn {
  width: 44px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.13);
}

.text-btn,
.primary-btn {
  min-width: 80px;
  padding: 0 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.13);
}

.primary-btn {
  min-width: 98px;
  color: white;
  background: var(--blue);
}

.text-btn.next-round {
  min-width: 112px;
  color: white;
  background: var(--good);
  box-shadow:
    0 9px 22px rgba(19, 133, 84, 0.32),
    0 0 0 3px rgba(255, 255, 255, 0.18);
}

.primary-btn:hover:not(:disabled) {
  background: var(--blue-dark);
}

.status {
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(5, 47, 40, 0.5);
  text-align: center;
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.status.win {
  color: white;
  background: rgba(19, 133, 84, 0.9);
}

.status.warn {
  color: #2b2105;
  background: var(--amber);
}

.status.fail {
  color: white;
  background: rgba(184, 52, 58, 0.88);
}

.side {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 253, 248, 0.9)),
    var(--panel);
  box-shadow: 0 18px 42px rgba(27, 43, 37, 0.11);
}

.side-block {
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.side-block:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.side-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.side-grid .side-block {
  border-bottom: 0;
  padding-bottom: 0;
}

.side-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.side p {
  margin: 0;
  line-height: 1.55;
}

.compact p {
  font-size: 18px;
}

@media (min-width: 901px) and (max-height: 820px) {
  .app {
    padding: 12px 0;
  }

  .topbar {
    align-items: center;
    margin-bottom: 10px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 42px;
    line-height: 1;
  }

  .lede {
    margin-top: 6px;
    font-size: 15px;
    line-height: 1.35;
  }

  .scoreboard span {
    min-width: 96px;
    padding: 7px 12px;
  }

  .game {
    grid-template-columns: minmax(0, 1fr) minmax(210px, 250px);
    gap: 12px;
  }

  .table {
    gap: 9px;
    padding: 14px;
  }

  .target {
    width: 84px;
    height: 84px;
  }

  .target span,
  .expression-label {
    font-size: 11px;
  }

  .target strong {
    margin-top: -5px;
    font-size: 38px;
  }

  .cards {
    grid-template-columns: repeat(4, minmax(76px, 112px));
    min-height: 142px;
  }

  .card {
    min-height: 142px;
    padding: 10px;
  }

  .card:hover:not(:disabled),
  .card:focus-visible {
    transform: translateY(-5px);
  }

  .card:disabled {
    transform: translateY(5px) scale(0.97);
  }

  .rank {
    font-size: 21px;
  }

  .suit {
    font-size: 19px;
  }

  .card-center {
    font-size: 46px;
  }

  .expression-wrap {
    gap: 5px;
  }

  .expression {
    min-height: 46px;
    padding: 7px;
  }

  .token {
    min-width: 34px;
    height: 34px;
  }

  .keypad,
  .actions {
    gap: 7px;
  }

  .key,
  .icon-btn,
  .text-btn,
  .primary-btn {
    min-height: 36px;
  }

  .key {
    width: 46px;
    font-size: 21px;
  }

  .icon-btn {
    width: 38px;
    font-size: 19px;
  }

  .text-btn,
  .primary-btn {
    min-width: 74px;
    padding: 0 12px;
  }

  .primary-btn {
    min-width: 88px;
  }

  .status {
    min-height: 40px;
    padding: 9px 12px;
  }

  .side {
    gap: 10px;
    padding: 14px;
  }

  .side-block,
  .side-grid {
    padding-bottom: 10px;
  }

  .side-label {
    margin-bottom: 5px;
    font-size: 11px;
  }

  .side p {
    line-height: 1.35;
  }
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .scoreboard {
    justify-content: flex-start;
  }

  .game {
    grid-template-columns: 1fr;
  }

  .table {
    min-height: 0;
  }

  .side {
    grid-template-columns: 1.2fr 1fr 1.1fr;
  }

  .side-block,
  .side-grid {
    padding-bottom: 0;
    border-bottom: 0;
  }
}

@media (max-width: 620px) {
  .app {
    width: min(100% - 20px, 1180px);
    padding: 18px 0;
  }

  h1 {
    font-size: 42px;
  }

  .lede {
    font-size: 15px;
  }

  .cards {
    grid-template-columns: repeat(2, minmax(118px, 1fr));
    min-height: 0;
  }

  .card {
    min-height: 172px;
  }

  .card-center {
    font-size: 54px;
  }

  .target {
    width: 106px;
    height: 106px;
  }

  .target strong {
    font-size: 44px;
  }

  .side {
    grid-template-columns: 1fr;
  }
}
