:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --surface: #ffffff;
  --line: #d9d9d2;
  --text: #242520;
  --muted: #717268;
  --accent: #1d6f62;
  --accent-dark: #155348;
  --danger: #9b342d;
  --shadow: 0 16px 36px rgba(30, 34, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 650;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

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

.language-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.language-control select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

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

.mini-stats span {
  min-width: 82px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
  text-align: center;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 24px;
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto;
  align-items: start;
}

.workspace {
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 30px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

h2 {
  font-size: 22px;
  font-weight: 650;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}

.setting-control {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbf9;
  padding: 14px;
  color: var(--muted);
  font-size: 14px;
}

.setting-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-label strong {
  color: var(--text);
  font-size: 18px;
  font-weight: 650;
  white-space: nowrap;
}

input[type="number"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.question-control .setting-label input {
  max-width: 100px;
  text-align: right;
}

button {
  min-height: 44px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 0 20px;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  padding: 0 16px;
}

.game-panel {
  display: grid;
  gap: 22px;
}

.question-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  min-height: 160px;
  align-content: center;
  text-align: center;
}

.question {
  font-size: clamp(46px, 9vw, 96px);
  font-weight: 620;
  line-height: 1.05;
  letter-spacing: 0;
}

.answer {
  min-height: 48px;
  color: var(--accent-dark);
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1.1;
  word-break: break-all;
}

.feedback {
  min-height: 24px;
  color: var(--muted);
  text-align: center;
}

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

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  gap: 10px;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}

.keypad button {
  aspect-ratio: 1.65 / 1;
  background: #f7f7f4;
  border-color: var(--line);
  color: var(--text);
  font-size: 24px;
}

.keypad button:hover {
  background: #eeeeea;
}

.game-actions {
  text-align: center;
}

.result-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 12px;
}

.result-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: #fbfbf9;
}

.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.result-grid strong {
  font-size: 22px;
  font-weight: 650;
}

.history-wrap {
  margin-top: 20px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: #f7f7f4;
}

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

.ad-slot {
  position: sticky;
  top: 18px;
  min-height: 280px;
  border: 1px dashed #bfc0b8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--muted);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  text-align: center;
  padding: 18px;
}

.ad-slot span {
  font-size: 12px;
  letter-spacing: 0.08em;
}

.ad-slot p {
  font-size: 14px;
}

.ad-fallback {
  display: grid;
  gap: 6px;
}

.adsense-container {
  width: 100%;
  min-height: 250px;
}

.adsense-container .adsbygoogle {
  min-height: 250px;
}

.site-info {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto 28px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.info-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 18px;
}

.info-panel h2 {
  margin-bottom: 10px;
  font-size: 18px;
}

.info-panel p {
  color: var(--muted);
  line-height: 1.7;
}

.contact-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  margin-top: 14px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent-dark);
  text-decoration: none;
}

.contact-link:hover {
  background: #edf5f2;
}

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

.info-head h2 {
  margin-bottom: 0;
}

.compact-button {
  min-height: 34px;
  padding: 0 12px;
}

.record-summary {
  margin-bottom: 12px;
}

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

.record-list li {
  color: var(--muted);
  line-height: 1.45;
}

.record-list strong {
  display: inline-block;
  margin: 0 8px;
  color: var(--text);
}

.record-list small {
  color: var(--muted);
}

.footer {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 22px 16px 34px;
  color: var(--muted);
  font-size: 14px;
}

.footer a {
  color: var(--accent-dark);
  text-decoration: none;
}

.is-hidden {
  display: none;
}

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

  .settings-grid,
  .result-grid,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .ad-slot {
    position: static;
    min-height: 90px;
  }
}

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

  .mini-stats {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-tools,
  .language-control {
    width: 100%;
  }

  .language-control select {
    flex: 1;
  }

  .mini-stats span {
    flex: 1;
  }

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

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

  .primary-button,
  .ghost-button {
    width: 100%;
  }
}
