:root {
  --bg: #f1e4cf;
  --bg-top: #fbf4ea;
  --panel: rgba(255, 249, 242, 0.9);
  --panel-strong: rgba(255, 252, 247, 0.96);
  --ink: #1b1713;
  --muted: #7c7267;
  --line: rgba(27, 23, 19, 0.08);
  --accent: #e36d33;
  --accent-2: #f2b661;
  --green: #2a8e82;
  --shadow: 0 24px 56px rgba(71, 45, 19, 0.1);
  --pattern: url("/img/pattern-light.png");
  --texture: url("/img/texture-light.webp");
}

body[data-theme="dark"] {
  --bg: #161b22;
  --bg-top: #1f2730;
  --panel: rgba(31, 37, 46, 0.86);
  --panel-strong: rgba(35, 42, 52, 0.94);
  --ink: #f6f0e7;
  --muted: #b8b0a7;
  --line: rgba(246, 240, 231, 0.1);
  --accent: #ff8d54;
  --accent-2: #ffc56f;
  --green: #34a593;
  --shadow: 0 24px 56px rgba(0, 0, 0, 0.32);
  --pattern: url("/img/pattern-dark.png.png");
  --texture: url("/img/texture-dark.webp");
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    var(--pattern) 0 0 / 420px 420px repeat,
    var(--texture) 0 0 / 250px 250px repeat,
    radial-gradient(circle at top left, rgba(227, 109, 51, 0.12), transparent 24%),
    radial-gradient(circle at bottom right, rgba(42, 142, 130, 0.1), transparent 28%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 100%);
}

button,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(14px);
}

.app-shell,
.tetris-shell {
  width: min(1280px, calc(100% - 24px));
  margin: 0 auto;
  padding: 72px 0 24px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.panel--inner {
  display: grid;
  gap: 14px;
  align-content: start;
}

.eyebrow,
.panel__kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--green);
}

h1,
h2,
h3,
p {
  margin: 0;
}

.auth-view {
  display: grid;
  gap: 18px;
  padding: 16px;
}

.auth-shell {
  display: grid;
  gap: 16px;
}

.auth-hero,
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) 320px;
  gap: 18px;
  align-items: end;
  padding: 6px 4px 2px;
}

.auth-hero__copy,
.hero__copy {
  display: grid;
  gap: 12px;
}

.auth-hero__copy h1,
.hero__copy h1 {
  font-size: clamp(2.3rem, 5vw, 4.4rem);
  line-height: 0.92;
  letter-spacing: -0.06em;
  max-width: 8ch;
}

.hero-note,
.hero__note,
.auth-card__head p:last-child,
.auth-status,
.controls-card p,
.topbar__note {
  color: var(--muted);
  line-height: 1.5;
}

.mode-row,
.auth-hero__chips,
.hero__chips,
.topbar__line,
.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-hero__chips span,
.hero__chips span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(23, 20, 17, 0.06);
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ink);
}

.mode-chip,
.ghost-link,
.code-chip,
.status-pill,
.icon-chip,
.team-join,
.ghost-button,
.primary-button,
.accent-button {
  border: 1px solid var(--line);
  border-radius: 16px;
}

.mode-chip,
.ghost-link,
.ghost-button,
.icon-chip,
.team-join {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 16px;
  background: rgba(27, 23, 19, 0.05);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  font-weight: 800;
}

.mode-chip.is-active {
  background: rgba(227, 109, 51, 0.14);
  border-color: rgba(227, 109, 51, 0.24);
  color: var(--accent);
}

.auth-hero__aside,
.hero__aside {
  display: grid;
  justify-items: end;
  gap: 12px;
  width: 100%;
  align-self: center;
  text-align: right;
}

.auth-hero__aside p,
.hero__aside p {
  max-width: 30ch;
}

.auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.auth-card {
  min-height: 280px;
  padding: 18px;
  gap: 16px;
  align-content: start;
  border-radius: 24px;
  border: 1px solid rgba(23, 20, 17, 0.08);
  box-shadow: 0 18px 40px rgba(26, 19, 12, 0.08);
}

.auth-card > button {
  justify-self: start;
  min-width: 148px;
}

.panel--inner button {
  justify-self: start;
  min-width: 148px;
}

.auth-card__head {
  display: grid;
  gap: 8px;
  align-content: start;
}

.auth-card__head h2 {
  font-size: clamp(1.7rem, 2vw, 2.2rem);
  line-height: 1;
}

.auth-footer {
  display: grid;
  gap: 10px;
}

#create-card-note {
  min-height: 48px;
}

#create-room-form {
  gap: 16px;
}

.auth-card--leader {
  background:
    radial-gradient(circle at top right, rgba(227, 109, 51, 0.12), transparent 26%),
    var(--panel);
}

.auth-card--player {
  background:
    radial-gradient(circle at top right, rgba(42, 142, 130, 0.12), transparent 26%),
    var(--panel);
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(23, 20, 17, 0.12);
  border-radius: 14px;
  background: var(--field-bg);
  color: var(--ink);
}

.primary-button,
.accent-button,
.ghost-button--strong {
  min-height: 52px;
  padding: 0 20px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #ff9a56);
  color: #fffaf2;
  border: none;
}

.accent-button {
  background: linear-gradient(135deg, var(--green), #3cb5a3);
  color: #f8fffd;
  border: none;
}

.ghost-button--strong {
  background: rgba(27, 23, 19, 0.05);
  color: var(--ink);
}

.auth-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.game-view {
  display: grid;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.topbar__line h2 {
  font-size: clamp(1.55rem, 1.8vw, 2rem);
}

.topbar__note {
  font-size: 0.92rem;
}

.topbar > div:first-child {
  display: grid;
  gap: 6px;
}

.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  background: rgba(27, 23, 19, 0.05);
  font-weight: 800;
  font-size: 0.92rem;
}

.icon-chip {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(23, 20, 17, 0.04);
  overflow: hidden;
  transition: transform 0.18s ease, background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.icon-chip svg {
  width: 20px;
  height: 20px;
  transition: transform 0.18s ease;
}

.icon-chip::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 900;
  color: #fff;
  opacity: 0;
  transform: scale(0.55);
}

.icon-chip--success {
  background: var(--green);
  border-color: rgba(22, 105, 94, 0.72);
  color: #fff;
  box-shadow:
    0 0 0 6px rgba(22, 105, 94, 0.14),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  animation: icon-chip-pop 0.42s ease;
}

.icon-chip--success svg {
  animation: icon-chip-hide 1.2s ease forwards;
}

.icon-chip--success::after {
  animation: icon-chip-check 1.2s ease forwards;
}

@keyframes icon-chip-pop {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.08);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes icon-chip-hide {
  0%,
  18% {
    opacity: 1;
    transform: scale(1);
  }

  30%,
  100% {
    opacity: 0;
    transform: scale(0.4);
  }
}

@keyframes icon-chip-check {
  0%,
  20% {
    opacity: 0;
    transform: scale(0.55);
  }

  34%,
  78% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(0.75);
  }
}

.game-layout {
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr) 258px;
  gap: 12px;
  align-items: start;
}

.side-panel,
.arena-panel,
.opponents-panel {
  padding: 14px;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 10px;
}

.panel__head,
.arena-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.teams-grid,
.opponents-grid {
  display: grid;
  gap: 10px;
}

.team-card,
.opponent-card,
.controls-card,
.stat-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.45);
}

.team-card {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.team-card__head,
.opponent-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.team-card__members {
  margin: 0;
  min-height: 22px;
  line-height: 1.45;
  color: var(--muted);
  font-size: 0.92rem;
}

.team-member--self {
  font-weight: 800;
  color: var(--accent);
}

.team-card--green .team-member--self,
.team-card--green .team-card__title {
  color: var(--green);
}

.team-card__title {
  font-weight: 800;
}

.team-join {
  min-height: 40px;
  min-width: 40px;
  width: 40px;
  padding: 0;
  border-radius: 14px;
  background: rgba(43, 167, 142, 0.12);
  border-color: rgba(43, 167, 142, 0.2);
  color: #14725f;
}

.team-join svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.team-join--leave {
  background: rgba(195, 64, 52, 0.12);
  border-color: rgba(195, 64, 52, 0.18);
  color: #9d342b;
}

.team-card__footer {
  display: flex;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.team-join:disabled,
.ghost-button:disabled,
.primary-button:disabled,
.accent-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.controls-card,
.stat-box {
  padding: 12px;
}

.controls-card {
  gap: 6px;
  font-size: 0.95rem;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 20, 17, 0.34);
  backdrop-filter: blur(3px);
}

.modal__card {
  position: relative;
  width: min(760px, 100%);
  max-height: min(85vh, 920px);
  padding: 20px;
  border-radius: 22px;
  border: 1px solid rgba(23, 20, 17, 0.1);
  background: rgba(255, 250, 242, 0.98);
  box-shadow: 0 24px 60px rgba(23, 20, 17, 0.2);
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.modal__body {
  display: grid;
  gap: 10px;
  max-height: calc(85vh - 110px);
  overflow-y: auto;
  padding-right: 4px;
}

.modal__body p {
  line-height: 1.45;
}

.help-intro {
  display: grid;
  gap: 8px;
}

.help-section {
  border: 1px solid rgba(23, 20, 17, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
  overflow: hidden;
}

.help-section summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  font-weight: 800;
}

.help-section summary::-webkit-details-marker {
  display: none;
}

.help-section summary::after {
  content: "+";
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(23, 20, 17, 0.08);
  font-size: 18px;
  line-height: 1;
}

.help-section[open] summary::after {
  content: "−";
}

.help-section__content {
  display: grid;
  gap: 14px;
  padding: 0 16px 16px;
}

.help-rule {
  display: grid;
  gap: 6px;
}

.help-rule strong {
  font-size: 15px;
}

.help-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 8px;
}

.arena-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 148px;
  gap: 12px;
  align-items: stretch;
}

.board-stack {
  position: relative;
  width: fit-content;
  justify-self: center;
}

.main-board,
.mini-board,
#next-board {
  display: block;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(12, 17, 22, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.main-board {
  width: min(100%, 320px);
  height: auto;
}

.overlay-banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-family: "Rubik Mono One", sans-serif;
  font-size: clamp(0.96rem, 1.7vw, 1.28rem);
  line-height: 1.1;
  color: #fff5e9;
  background: linear-gradient(180deg, rgba(16, 21, 27, 0.28), rgba(16, 21, 27, 0.56));
  border-radius: 22px;
  pointer-events: none;
}

.stats-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.stat-box {
  display: grid;
  gap: 6px;
}

.stat-box span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.stat-box strong {
  font-size: 1.35rem;
  line-height: 1;
}

.stat-box--warn strong {
  color: var(--accent);
}

.status-pill {
  min-height: 34px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  background: rgba(27, 23, 19, 0.05);
  font-weight: 800;
  font-size: 0.88rem;
}

.opponent-card {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.mini-board {
  width: 100%;
  height: auto;
  max-width: 132px;
  justify-self: center;
}

.opponent-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
}

.opponent-card__head strong,
.team-card__title {
  font-size: 0.95rem;
}

#restart-solo,
#start-match {
  min-height: 46px;
  width: 100%;
  justify-content: center;
  position: relative;
  z-index: 0;
}

#next-board {
  width: 100%;
  height: auto;
  max-width: 120px;
  justify-self: center;
}

body[data-theme="dark"] input,
body[data-theme="dark"] .team-card,
body[data-theme="dark"] .opponent-card,
body[data-theme="dark"] .controls-card,
body[data-theme="dark"] .stat-box,
body[data-theme="dark"] .modal__card,
body[data-theme="dark"] .help-section,
body[data-theme="dark"] .ghost-link,
body[data-theme="dark"] .ghost-button,
body[data-theme="dark"] .ghost-button--strong,
body[data-theme="dark"] .icon-chip,
body[data-theme="dark"] .mode-chip,
body[data-theme="dark"] .team-join,
body[data-theme="dark"] .code-chip,
body[data-theme="dark"] .status-pill {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(246, 240, 231, 0.1);
  color: #f6f0e7;
}

body[data-theme="dark"] .modal__head h3,
body[data-theme="dark"] .help-rule strong {
  color: #f5efe6;
}

body[data-theme="dark"] .team-join {
  background: rgba(43, 167, 142, 0.2);
  border-color: rgba(67, 204, 176, 0.28);
  color: #dff8f2;
}

body[data-theme="dark"] .team-join--leave {
  background: rgba(195, 64, 52, 0.2);
  border-color: rgba(224, 103, 91, 0.26);
  color: #ffe1dc;
}

body[data-theme="dark"] .mode-chip.is-active {
  background: rgba(255, 141, 84, 0.14);
  border-color: rgba(255, 141, 84, 0.22);
  color: var(--accent);
}

body[data-theme="dark"] .modal__card {
  background: rgba(34, 40, 49, 0.96);
  border-color: rgba(245, 239, 230, 0.1);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
}

body[data-theme="dark"] .help-section {
  background: rgba(41, 48, 58, 0.94);
  border-color: rgba(245, 239, 230, 0.1);
}

body[data-theme="dark"] .modal__backdrop {
  background: rgba(10, 12, 16, 0.56);
}

body[data-theme="dark"] .team-card__member span,
body[data-theme="dark"] .hero__note,
body[data-theme="dark"] .auth-card__head p:last-child,
body[data-theme="dark"] .auth-status,
body[data-theme="dark"] .controls-card p,
body[data-theme="dark"] .topbar__note,
body[data-theme="dark"] .stat-box span,
body[data-theme="dark"] .modal__body p,
body[data-theme="dark"] .help-list,
body[data-theme="dark"] .opponent-card__meta {
  color: #b8b0a7;
}

body[data-theme="dark"] .help-section summary::after {
  background: rgba(255, 255, 255, 0.08);
}

@keyframes copy-pop {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(42, 142, 130, 0.16);
  }

  25% {
    transform: scale(1.08);
    box-shadow: 0 0 0 6px rgba(42, 142, 130, 0.14);
  }

  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(42, 142, 130, 0);
  }
}

@media (max-width: 1080px) {
  .auth-grid,
  .game-layout,
  .arena-stage,
  .hero {
    grid-template-columns: 1fr;
  }

  .hero__visual {
    width: 180px;
    height: 132px;
    justify-self: start;
    padding-right: 0;
  }

  .hero__back {
    position: static;
    justify-self: start;
  }

  .hero__aside {
    justify-items: start;
    text-align: left;
  }

  .stats-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-panel .stat-box:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
    padding: 10px 14px;
  }

  .tetris-shell {
    width: min(100% - 16px, 1260px);
    padding-top: 72px;
  }

  .auth-view,
  .side-panel,
  .arena-panel,
  .opponents-panel,
  .topbar {
    padding: 16px;
  }

  .topbar,
  .panel__head,
  .arena-head {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar__actions {
    justify-content: stretch;
  }

  .topbar__actions > * {
    width: 100%;
  }
}

/* Shared auth hard sync */
.auth-view .auth-card,
.auth-view .panel--inner.auth-card {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
}

.auth-view .auth-card > .primary-button,
.auth-view .auth-card > .accent-button,
.auth-view .auth-card > button.primary-button,
.auth-view .auth-card > button.accent-button,
.auth-view .auth-card > button {
  display: inline-flex !important;
  align-self: stretch !important;
  justify-content: center !important;
  width: 100% !important;
  inline-size: 100% !important;
  min-inline-size: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin-top: auto !important;
  margin-bottom: 0 !important;
  flex: 0 0 auto !important;
}
