:root {
  --bg: #000000;
  --panel: #242424;
  --panel-soft: #111111;
  --text: #f7f7f7;
  --muted: #cbcbcb;
  --border: #333333;
  --track: #444444;
  --player-one: #ff4b3e;
  --player-two: #3297ff;
  --drawer: rgba(18, 18, 18, 0.97);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.orientation-lock {
  display: none;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

.scoreboard-app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 8px;
  padding: 10px 18px 12px;
  background: #000;
  overflow: hidden;
}

.top-bar {
  display: grid;
  grid-template-columns: 72px 1fr 140px;
  align-items: center;
  gap: 18px;
}

.icon-button {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.brand-lockup {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.brand-logo,
.drawer-logo,
.rotate-logo {
  width: 54px;
  height: 54px;
}

.brand-line,
.drawer-kicker,
.section-title {
  margin: 0;
  font-size: clamp(0.95rem, 1.5vw, 1.25rem);
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  letter-spacing: 0.05em;
}

.brand-lockup strong {
  font-size: 0.95rem;
  color: var(--muted);
}

.total-wrap,
.round-wrap {
  margin: 0 auto;
  width: min(100%, 1520px);
}

.section-title {
  text-align: center;
  margin-bottom: 4px;
}

.total-grid,
.round-grid {
  display: grid;
  grid-template-columns: 170px 1fr 1fr 170px;
  gap: 10px;
  align-items: center;
}

.player-name {
  text-align: center;
}

.player-name input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: center;
  font-size: clamp(1.15rem, 2vw, 1.85rem);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-weight: 700;
  padding: 0 8px;
  line-height: 1;
}

.score-box,
.round-score-box {
  background: var(--panel);
  border-radius: 4px;
  min-height: 0;
  height: clamp(150px, 24vh, 214px);
  display: flex;
  justify-content: center;
  align-items: center;
}

.round-score-box {
  height: clamp(160px, 27vh, 236px);
}

.score-value {
  font-size: clamp(3.9rem, 10vw, 7.6rem);
  font-weight: 400;
  line-height: 1;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
}

.player-one-color {
  color: var(--player-one);
}

.player-two-color {
  color: var(--player-two);
}

.side-controls {
  display: grid;
  gap: 8px;
  align-content: center;
  padding: 0 10px;
}

.stat-row,
.step-row {
  display: flex;
  justify-content: center;
  gap: 18px;
  align-items: center;
}

.stat-row {
  font-size: clamp(1.5rem, 2.5vw, 2.4rem);
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
}

.stat-value {
  min-width: 30px;
  text-align: left;
}

.flat-button {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: clamp(2rem, 3vw, 3rem);
  width: 56px;
  height: 42px;
}

.round-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}

.round-actions button,
.inline-actions button,
#settingsForm button,
.settings-grid button,
.saved-game button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: #f1f1f1;
  color: #000;
  font-size: 0.95rem;
}

.secondary-button,
.ghost-button {
  background: #303030 !important;
  color: var(--text) !important;
}

.danger-button {
  background: #7d1717 !important;
  color: #fff !important;
}

.status-strip {
  width: min(100%, 1520px);
  margin: 0 auto;
  padding: 10px 14px;
  border-radius: 10px;
  background: #111;
  color: var(--muted);
  text-align: center;
  font-family: "Segoe UI", sans-serif;
}

.status-strip.success {
  color: #9ef0b4;
}

.history-list,
.saved-games,
.rules-list {
  display: grid;
  gap: 8px;
  font-family: "Segoe UI", sans-serif;
}

.history-list {
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.history-item,
.saved-game,
.rules-list article {
  background: #171717;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.history-item,
.saved-game {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.history-item p,
.saved-game p,
.rules-list p {
  margin: 0;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 10px 0;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  width: min(440px, calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right)));
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: var(--drawer);
  border-right: 1px solid var(--border);
  box-shadow: 24px 0 50px rgba(0, 0, 0, 0.35);
}

.history-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 11;
  width: min(420px, calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right)));
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(10, 10, 10, 0.98);
  border-left: 1px solid var(--border);
  box-shadow: -24px 0 50px rgba(0, 0, 0, 0.35);
}

.history-drawer-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.history-drawer-header h2 {
  margin: 0;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  letter-spacing: 0.05em;
}

.drawer-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.drawer-header h2,
.drawer-section h3 {
  margin: 0;
}

.drawer-section {
  padding-top: 16px;
  margin-top: 16px;
  border-top: 1px solid var(--border);
  font-family: "Segoe UI", sans-serif;
}

.drawer-section h3 {
  margin-bottom: 10px;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  letter-spacing: 0.05em;
}

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

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

.field span {
  color: var(--muted);
}

.field input,
.field select,
.auth-grid input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #101010;
  color: var(--text);
  padding: 10px 12px;
  font-family: "Segoe UI", sans-serif;
}

.field input[type="color"] {
  min-height: 48px;
  padding: 6px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.copyright {
  margin: 14px 0 4px;
  color: #8b8b8b;
  font-size: 0.85rem;
  text-align: center;
}

@media (max-width: 980px) {
  .top-bar {
    grid-template-columns: 60px 1fr 124px;
  }

  .total-grid,
  .round-grid {
    grid-template-columns: 122px 1fr 1fr 122px;
  }

  .score-box,
  .round-score-box {
    height: clamp(128px, 22vh, 170px);
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  :root {
    --mobile-safe-left: max(54px, calc(env(safe-area-inset-left) + 12px));
    --mobile-safe-right: max(18px, calc(env(safe-area-inset-right) + 10px));
  }

  html,
  body,
  .app-shell {
    overflow: hidden;
  }

  .drawer,
  .history-drawer {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-right: var(--mobile-safe-right);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: var(--mobile-safe-left);
  }

  .drawer {
    width: min(360px, calc(100vw - var(--mobile-safe-left) - var(--mobile-safe-right)));
  }

  .scoreboard-app {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: max(4px, env(safe-area-inset-top)) var(--mobile-safe-right) max(6px, env(safe-area-inset-bottom)) var(--mobile-safe-left);
    gap: 2px;
    overflow: hidden;
  }

  .total-wrap {
    display: flex;
    flex: 0 0 26%;
    flex-direction: column;
    min-height: 0;
  }

  .round-wrap {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
  }

  .brand-logo,
  .drawer-logo,
  .rotate-logo {
    width: 34px;
    height: 34px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    font-size: 1.2rem;
    border-radius: 10px;
  }

  .top-bar {
    grid-template-columns: 34px 1fr 104px;
    gap: 4px;
  }

  .top-actions {
    gap: 0;
  }

  .brand-lockup {
    gap: 6px;
  }

  .total-grid,
  .round-grid {
    grid-template-columns: 62px minmax(0, 1fr) minmax(0, 1fr) 62px;
    gap: 3px;
    flex: 1 1 auto;
    min-height: 0;
    align-self: stretch;
  }

  .brand-line,
  .drawer-kicker,
  .section-title {
    font-size: 0.7rem;
  }

  .total-wrap .section-title {
    display: none;
  }

  .brand-lockup strong {
    display: block;
    font-size: 0.68rem;
  }

  .player-name input {
    font-size: 0.76rem;
    padding: 0 2px;
  }

  .side-controls {
    gap: 2px;
    padding: 0 2px;
  }

  .stat-row {
    font-size: 0.78rem;
    gap: 4px;
  }

  .step-row {
    gap: 4px;
  }

  .flat-button {
    font-size: 1.1rem;
    width: 24px;
    height: 20px;
  }

  .round-actions {
    margin-top: 0;
    gap: 6px;
  }

  .round-actions button {
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  .score-box {
    height: 100%;
    min-height: 0;
  }

  .round-score-box {
    height: 100%;
    min-height: 0;
  }

  .score-value {
    font-size: clamp(2.2rem, 6.8vw, 3.8rem);
  }

  .status-strip {
    width: 100%;
    padding: 5px 8px;
    font-size: 0.76rem;
    border-radius: 6px;
    flex: 0 0 auto;
  }

  .total-wrap,
  .round-wrap {
    width: 100%;
  }

  .section-title {
    margin-bottom: 1px;
  }

  .history-drawer {
    width: min(340px, calc(100vw - var(--mobile-safe-left) - var(--mobile-safe-right)));
  }

  .history-list,
  .saved-games,
  .rules-list {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

@media (orientation: landscape) and (max-height: 430px) {
  :root {
    --mobile-safe-left: max(58px, calc(env(safe-area-inset-left) + 14px));
    --mobile-safe-right: max(16px, calc(env(safe-area-inset-right) + 8px));
  }

  .drawer,
  .history-drawer {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-right: var(--mobile-safe-right);
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: var(--mobile-safe-left);
  }

  .scoreboard-app {
    padding: max(4px, env(safe-area-inset-top)) var(--mobile-safe-right) max(6px, env(safe-area-inset-bottom)) var(--mobile-safe-left);
    gap: 2px;
  }

  .total-wrap {
    flex-basis: 24%;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .top-bar {
    grid-template-columns: 30px 1fr 94px;
  }

  .icon-button {
    width: 28px;
    height: 28px;
    font-size: 1rem;
  }

  .brand-line,
  .drawer-kicker,
  .section-title {
    font-size: 0.64rem;
  }

  .brand-lockup strong,
  .player-name input {
    font-size: 0.64rem;
  }

  .total-grid,
  .round-grid {
    grid-template-columns: 56px minmax(0, 1fr) minmax(0, 1fr) 56px;
    gap: 2px;
  }

  .score-box {
    height: 100%;
  }

  .round-score-box {
    height: 100%;
  }

  .score-value {
    font-size: clamp(1.9rem, 6vw, 3.1rem);
  }

  .stat-row {
    font-size: 0.7rem;
    gap: 3px;
  }

  .flat-button {
    width: 22px;
    height: 18px;
    font-size: 0.95rem;
  }

  .round-actions button {
    padding: 5px 8px;
    font-size: 0.72rem;
  }

  .status-strip {
    padding: 4px 6px;
    font-size: 0.7rem;
  }
}

@media (max-width: 840px) and (orientation: portrait) {
  .orientation-lock {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    text-align: center;
    padding: 24px;
    background: #000;
  }

  .orientation-lock h1,
  .orientation-lock p {
    margin: 0;
  }

  .app-shell {
    display: none;
  }
}
