:root {
  color-scheme: light;
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --ink: #17202a;
  --muted: #657180;
  --line: #d9e1e8;
  --primary: #1769c2;
  --primary-dark: #10549d;
  --teal: #18756c;
  --amber: #b87514;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(24, 35, 48, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #ffffff 0%, var(--bg) 56%, #e8edf2 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--primary);
  cursor: pointer;
  font-weight: 800;
  transition: background-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

button:hover {
  background: var(--primary-dark);
  box-shadow: 0 8px 18px rgba(23, 105, 194, 0.18);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  box-shadow: none;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
p {
  margin: 0;
}

.portal-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.portal-header {
  display: grid;
  grid-template-columns: minmax(220px, auto) minmax(0, 1fr);
  gap: 18px;
  align-items: end;
  margin-bottom: 16px;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.portal-header h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.06;
  letter-spacing: 0;
}

.game-switcher {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.game-tab {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: none;
}

.game-tab:hover {
  color: var(--primary-dark);
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(24, 35, 48, 0.08);
}

.game-tab.active {
  border-color: rgba(23, 105, 194, 0.36);
  color: #ffffff;
  background: var(--primary);
}

.game-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
}

.game-summary h2 {
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.12;
  letter-spacing: 0;
}

.game-summary p:last-child {
  max-width: 760px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.game-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.game-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 0 11px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 430px);
  gap: 18px;
  align-items: start;
}

.play-frame-panel,
.data-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.play-frame-panel {
  overflow: hidden;
}

.frame-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 0 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.frame-toolbar a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 0 10px;
  color: var(--primary-dark);
  white-space: nowrap;
}

#gameFrame {
  display: block;
  width: 100%;
  height: min(78vh, 820px);
  min-height: 640px;
  border: 0;
  background: #f7f9fb;
}

.side-stack {
  display: grid;
  gap: 18px;
}

.data-panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.panel-head h2 {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel-head button {
  min-height: 36px;
  padding: 0 12px;
  background: var(--teal);
}

.panel-head button:hover {
  background: #145f58;
  box-shadow: 0 8px 18px rgba(24, 117, 108, 0.18);
}

.panel-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.leaderboard-panel .panel-message {
  padding: 12px 16px 0;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 360px;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 9px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

td {
  color: var(--ink);
}

td:first-child,
th:first-child {
  padding-left: 16px;
}

td:last-child,
th:last-child {
  padding-right: 16px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.rank-cell,
.number-cell,
.duration-cell {
  font-variant-numeric: tabular-nums;
}

.muted-cell,
.empty-cell {
  color: var(--muted);
}

.empty-cell {
  padding: 18px 16px;
  text-align: center;
}

.comment-form {
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.comment-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.comment-form input,
.comment-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: 0;
}

.comment-form input {
  height: 40px;
  padding: 0 11px;
}

.comment-form textarea {
  min-height: 86px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.55;
}

.comment-form input:focus,
.comment-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 105, 194, 0.14);
}

.comment-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.comment-actions button {
  min-height: 38px;
  padding: 0 16px;
  background: var(--amber);
}

.comment-actions button:hover {
  background: #945f11;
  box-shadow: 0 8px 18px rgba(184, 117, 20, 0.18);
}

.comment-list {
  display: grid;
  max-height: 360px;
  overflow-y: auto;
}

.comment-item {
  display: grid;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.comment-item:last-child {
  border-bottom: 0;
}

.comment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.comment-meta strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment-meta time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.comment-item p {
  color: #2c3744;
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.empty-state {
  padding: 18px 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.is-error {
  color: var(--danger);
}

.is-success {
  color: var(--teal);
}

@media (max-width: 1180px) {
  .play-layout {
    grid-template-columns: 1fr;
  }

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

  #gameFrame {
    height: 760px;
  }
}

@media (max-width: 780px) {
  .portal-shell {
    width: min(100% - 24px, 760px);
    padding-top: 16px;
  }

  .portal-header,
  .game-summary {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .game-switcher,
  .game-meta {
    justify-content: start;
  }

  .game-tab {
    flex: 1 1 0;
    min-width: 112px;
  }

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

  #gameFrame {
    height: 720px;
    min-height: 560px;
  }
}

@media (max-width: 520px) {
  .portal-shell {
    width: min(100% - 18px, 520px);
  }

  .game-tab {
    flex-basis: calc(50% - 5px);
    padding: 0 10px;
  }

  .frame-toolbar {
    align-items: stretch;
    flex-direction: column;
    justify-content: center;
    padding: 10px;
  }

  .frame-toolbar a {
    justify-content: center;
    width: 100%;
  }

  #gameFrame {
    height: 680px;
    min-height: 520px;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-head button {
    width: 100%;
  }

  .comment-actions {
    grid-template-columns: 1fr;
  }
}
