:root {
  --bg: #eef4f8;
  --surface: #ffffff;
  --surface-2: #f6f9fc;
  --ink: #162231;
  --muted: #66778a;
  --line: #d8e2ec;
  --brand: #1261a6;
  --brand-dark: #0b3d66;
  --teal: #159184;
  --amber: #e9a208;
  --rose: #cf4968;
  --green: #2f8f46;
  --shadow: 0 18px 42px rgba(18, 36, 64, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #edf5fb 0%, #f8fafc 48%, #eef4f8 100%);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

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

.portal-link {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid rgba(18, 97, 166, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: var(--brand-dark);
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 12px 28px rgba(18, 36, 64, 0.13);
  backdrop-filter: blur(10px);
}

.game-shell {
  width: min(100% - 32px, 1160px);
  margin: 0 auto;
  padding: 76px 0 34px;
}

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

.game-header h1 {
  margin: 0;
  color: var(--brand-dark);
  font-size: 44px;
  line-height: 1.06;
}

.game-header p {
  max-width: 720px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 17px;
}

.author-pill {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

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

.play-panel,
.side-panel,
.ad-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.play-panel {
  min-height: 560px;
  padding: 22px;
}

.side-panel {
  padding: 18px;
}

.side-panel h2,
.play-panel h2 {
  margin: 0 0 12px;
  color: var(--brand-dark);
  font-size: 24px;
}

.stats {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.stat span:first-child {
  color: var(--muted);
  font-weight: 700;
}

.stat strong {
  color: var(--ink);
  font-size: 20px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.btn:hover,
.btn:focus-visible {
  background: #0f5592;
  outline: none;
}

.btn.secondary {
  background: #e7eef5;
  color: var(--brand-dark);
}

.btn.secondary:hover,
.btn.secondary:focus-visible {
  background: #dbe8f2;
}

.note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.ad-box {
  margin-top: 14px;
  padding: 16px;
  border-style: dashed;
  background: repeating-linear-gradient(135deg, rgba(18, 97, 166, 0.05) 0 12px, rgba(21, 145, 132, 0.05) 12px 24px), #fff;
}

.ad-box strong {
  display: block;
  color: var(--brand-dark);
}

.ad-box span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.message {
  min-height: 44px;
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius);
  background: #eef6ff;
  color: var(--brand-dark);
  font-weight: 800;
}

.grid-board {
  display: grid;
  gap: 8px;
  width: min(100%, 560px);
  margin: 0 auto;
}

.tile-button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.tile-button:hover,
.tile-button:focus-visible,
.tile-button.selected {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px rgba(18, 97, 166, 0.12);
}

.color-prompt {
  min-height: 120px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: var(--radius);
  background: #102a43;
  color: #fff;
  text-align: center;
  font-size: 34px;
  font-weight: 900;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.color-choice {
  min-height: 86px;
  border: 3px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.38);
}

.word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 88px;
  margin-bottom: 18px;
}

.letter-box {
  width: 48px;
  height: 58px;
  display: grid;
  place-items: center;
  border-bottom: 4px solid var(--brand);
  color: var(--brand-dark);
  font-size: 30px;
  font-weight: 900;
}

.keyboard {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 7px;
}

.keyboard .tile-button {
  min-height: 44px;
  padding: 0;
}

.keyboard .tile-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.board-2048 {
  display: grid;
  grid-template-columns: repeat(4, minmax(58px, 1fr));
  gap: 10px;
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 10px;
  border-radius: var(--radius);
  background: #9ca7b3;
}

.tile-2048 {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #dbe3ea;
  color: #1f2937;
  font-size: 30px;
  font-weight: 900;
}

.memory-board {
  grid-template-columns: repeat(4, minmax(58px, 1fr));
  max-width: 540px;
}

.memory-card {
  aspect-ratio: 1 / 1;
  font-size: 34px;
  background: #125b8f;
  color: transparent;
}

.memory-card.open,
.memory-card.matched {
  background: #ffffff;
  color: var(--brand-dark);
}

.memory-card.matched {
  border-color: var(--green);
  background: #e9f7ed;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(34px, 1fr));
  width: min(100%, 560px);
  margin: 0 auto 18px;
  border: 2px solid var(--brand-dark);
}

.chess-square {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border: 0;
  font-size: 34px;
}

.chess-square.light {
  background: #ecdfc6;
}

.chess-square.dark {
  background: #6a8a64;
}

.option-list {
  display: grid;
  gap: 10px;
}

.option-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.option-button:hover,
.option-button:focus-visible {
  border-color: var(--brand);
  outline: none;
}

.bubble-board,
.lines-board {
  display: grid;
  gap: 6px;
  width: min(100%, 560px);
  margin: 0 auto;
}

.bubble-board {
  grid-template-columns: repeat(8, minmax(32px, 1fr));
}

.lines-board {
  grid-template-columns: repeat(9, minmax(28px, 1fr));
}

.bubble-cell,
.line-cell {
  aspect-ratio: 1 / 1;
  border: 1px solid #c7d3df;
  border-radius: 50%;
  background: #eef3f8;
  cursor: pointer;
}

.line-cell {
  border-radius: 7px;
  background: #eef3f8;
}

.bubble-cell.selected,
.line-cell.selected {
  box-shadow: 0 0 0 4px rgba(18, 97, 166, 0.22);
}

.sudoku-wrap {
  display: grid;
  gap: 16px;
  justify-items: center;
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(28px, 1fr));
  width: min(100%, 540px);
  border: 3px solid var(--brand-dark);
  background: var(--brand-dark);
  gap: 1px;
}

.sudoku-cell {
  aspect-ratio: 1 / 1;
  border: 0;
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
}

.sudoku-cell.given {
  background: #e7eef5;
  color: var(--brand-dark);
  cursor: default;
}

.sudoku-cell.selected {
  background: #cfe9ff;
}

.sudoku-cell.error {
  background: #ffe4ea;
  color: #9f1239;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(5, minmax(46px, 1fr));
  gap: 8px;
  width: min(100%, 420px);
}

.quiz-question {
  min-height: 120px;
  padding: 20px;
  border-radius: var(--radius);
  background: #102a43;
  color: #fff;
  font-size: 26px;
  font-weight: 900;
}

.canvas-wrap {
  display: grid;
  place-items: center;
  min-height: 420px;
}

canvas {
  max-width: 100%;
  border-radius: var(--radius);
  background: #0f172a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

@media (max-width: 900px) {
  .portal-link {
    position: static;
    margin: 12px 0 0 16px;
  }

  .game-shell {
    padding-top: 18px;
  }

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

  .game-header h1 {
    font-size: 36px;
  }

  .author-pill {
    width: fit-content;
  }
}

@media (max-width: 520px) {
  .game-shell {
    width: min(100% - 22px, 1160px);
  }

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

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

  .btn {
    width: 100%;
  }
}
