@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;800;900&display=swap');

:root {
  --bg:           #faf8ef;
  --text:         #776e65;
  --text-light:   #f9f6f2;
  --board-bg:     #bbada0;
  --cell-bg:      rgba(238, 228, 218, 0.35);
  --btn-bg:       #8f7a66;
  --btn-hover:    #7c6b5a;
  --score-bg:     #bbada0;
  --overlay-bg:   rgba(238, 228, 218, 0.9);
  --modal-bg:     #faf8ef;
  --modal-shadow: rgba(119, 110, 101, 0.3);
  --border-color: #d4c5b5;
  --rank-gold:    #e6b800;
  --rank-silver:  #aaaaaa;
  --rank-bronze:  #b87333;
  --notice-bg:    rgba(119, 110, 101, 0.1);
  --transition:   0.3s ease;
}

[data-theme="dark"] {
  --bg:           #1a1a2e;
  --text:         #e0d7cc;
  --text-light:   #f9f6f2;
  --board-bg:     #2d2d44;
  --cell-bg:      rgba(255, 255, 255, 0.07);
  --btn-bg:       #6c5ce7;
  --btn-hover:    #5a4ecf;
  --score-bg:     #2d2d44;
  --overlay-bg:   rgba(26, 26, 46, 0.92);
  --modal-bg:     #16213e;
  --modal-shadow: rgba(0, 0, 0, 0.5);
  --border-color: #3d3d5c;
  --notice-bg:    rgba(108, 92, 231, 0.12);
}

[data-theme="forest"] {
  --bg:           #1b2d1e;
  --text:         #c8e6c9;
  --text-light:   #f1f8e9;
  --board-bg:     #2e4a2f;
  --cell-bg:      rgba(200, 230, 201, 0.12);
  --btn-bg:       #388e3c;
  --btn-hover:    #2e7d32;
  --score-bg:     #2e4a2f;
  --overlay-bg:   rgba(27, 45, 30, 0.92);
  --modal-bg:     #1b2d1e;
  --modal-shadow: rgba(0, 0, 0, 0.5);
  --border-color: #3a5c3c;
  --notice-bg:    rgba(56, 142, 60, 0.12);
}

[data-theme="ocean"] {
  --bg:           #0d1b2a;
  --text:         #b8d4e8;
  --text-light:   #e8f4fd;
  --board-bg:     #1a3a5c;
  --cell-bg:      rgba(184, 212, 232, 0.1);
  --btn-bg:       #1565c0;
  --btn-hover:    #0d47a1;
  --score-bg:     #1a3a5c;
  --overlay-bg:   rgba(13, 27, 42, 0.92);
  --modal-bg:     #0d1b2a;
  --modal-shadow: rgba(0, 0, 0, 0.5);
  --border-color: #1e4976;
  --notice-bg:    rgba(21, 101, 192, 0.12);
}

[data-theme="candy"] {
  --bg:           #fff0f5;
  --text:         #c2185b;
  --text-light:   #ffffff;
  --board-bg:     #f8bbd0;
  --cell-bg:      rgba(194, 24, 91, 0.1);
  --btn-bg:       #e91e63;
  --btn-hover:    #c2185b;
  --score-bg:     #f8bbd0;
  --overlay-bg:   rgba(255, 240, 245, 0.92);
  --modal-bg:     #fff0f5;
  --modal-shadow: rgba(194, 24, 91, 0.25);
  --border-color: #f48fb1;
  --notice-bg:    rgba(233, 30, 99, 0.1);
}

[data-theme="sunset"] {
  --bg:           #1c0a00;
  --text:         #ffd4a3;
  --text-light:   #fff8f0;
  --board-bg:     #7c2d00;
  --cell-bg:      rgba(255, 100, 0, 0.15);
  --btn-bg:       #e65100;
  --btn-hover:    #bf360c;
  --score-bg:     #7c2d00;
  --overlay-bg:   rgba(28, 10, 0, 0.92);
  --modal-bg:     #1c0a00;
  --modal-shadow: rgba(230, 81, 0, 0.3);
  --border-color: #a33a00;
  --notice-bg:    rgba(230, 81, 0, 0.12);
}

[data-theme="neon"] {
  --bg:           #060612;
  --text:         #e0e0ff;
  --text-light:   #ffffff;
  --board-bg:     #0d0d2b;
  --cell-bg:      rgba(0, 255, 255, 0.05);
  --btn-bg:       #00e5ff;
  --btn-hover:    #00b0cc;
  --score-bg:     #0d0d2b;
  --overlay-bg:   rgba(6, 6, 18, 0.94);
  --modal-bg:     #060612;
  --modal-shadow: rgba(0, 229, 255, 0.2);
  --border-color: #1a1a4a;
  --notice-bg:    rgba(0, 229, 255, 0.07);
}

[data-theme="ink"] {
  --bg:           #f5f0e8;
  --text:         #1a1208;
  --text-light:   #f5f0e8;
  --board-bg:     #2c2318;
  --cell-bg:      rgba(44, 35, 24, 0.1);
  --btn-bg:       #2c2318;
  --btn-hover:    #1a1208;
  --score-bg:     #2c2318;
  --overlay-bg:   rgba(245, 240, 232, 0.92);
  --modal-bg:     #f5f0e8;
  --modal-shadow: rgba(44, 35, 24, 0.3);
  --border-color: #c8b89a;
  --notice-bg:    rgba(44, 35, 24, 0.07);
}

[data-theme="gold"] {
  --bg:           #1a1200;
  --text:         #ffd700;
  --text-light:   #fff8dc;
  --board-bg:     #3d2d00;
  --cell-bg:      rgba(255, 215, 0, 0.1);
  --btn-bg:       #b8860b;
  --btn-hover:    #8b6914;
  --score-bg:     #3d2d00;
  --overlay-bg:   rgba(26, 18, 0, 0.92);
  --modal-bg:     #1a1200;
  --modal-shadow: rgba(184, 134, 11, 0.4);
  --border-color: #5a4200;
  --notice-bg:    rgba(184, 134, 11, 0.12);
}

[data-theme="aurora"] {
  --bg:           #0a1628;
  --text:         #a8edea;
  --text-light:   #e0fffe;
  --board-bg:     #0d2240;
  --cell-bg:      rgba(168, 237, 234, 0.08);
  --btn-bg:       #00897b;
  --btn-hover:    #00695c;
  --score-bg:     #0d2240;
  --overlay-bg:   rgba(10, 22, 40, 0.92);
  --modal-bg:     #0a1628;
  --modal-shadow: rgba(0, 137, 123, 0.3);
  --border-color: #1a3a5c;
  --notice-bg:    rgba(0, 137, 123, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Nunito', sans-serif;
}

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding: 16px;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.container {
  width: 100%;
  max-width: 520px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

h1 {
  font-size: 56px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -2px;
  line-height: 1;
}

.scores {
  display: flex;
  gap: 8px;
}

.score-box {
  background: var(--score-bg);
  color: var(--text-light);
  padding: 8px 14px;
  border-radius: 8px;
  text-align: center;
  min-width: 90px;
  transition: background var(--transition);
}

.score-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.85;
}

.score-value {
  font-size: 22px;
  font-weight: 900;
}

.theme-bar {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.theme-label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.6;
  margin-right: 2px;
}

.theme-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
  flex-shrink: 0;
  position: relative;
}

.theme-dot:hover {
  transform: scale(1.18);
}

.theme-dot.active {
  border-color: var(--text);
  transform: scale(1.12);
}

.theme-dot[data-theme="light"]  { background: #bbada0; }
.theme-dot[data-theme="dark"]   { background: #6c5ce7; }
.theme-dot[data-theme="forest"] { background: #388e3c; }
.theme-dot[data-theme="ocean"]  { background: #1565c0; }
.theme-dot[data-theme="candy"]  { background: #e91e63; }
.theme-dot[data-theme="sunset"] { background: linear-gradient(135deg, #e65100, #ff6d00); }
.theme-dot[data-theme="neon"]   { background: #00e5ff; }
.theme-dot[data-theme="ink"]    { background: #2c2318; }
.theme-dot[data-theme="gold"]   { background: linear-gradient(135deg, #b8860b, #ffd700); }
.theme-dot[data-theme="aurora"] { background: linear-gradient(135deg, #00897b, #26c6da); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  background: var(--btn-bg);
  color: var(--text-light);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s, opacity 0.2s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--btn-hover);
}

.btn:active {
  transform: scale(0.96);
}

.btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--text-light);
  color: var(--text-light);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-record-skip {
  border-color: var(--border-color);
  color: var(--text);
}

.btn-record-skip:hover {
  background: var(--cell-bg);
}

.btn-undo {
  background: var(--border-color);
  color: var(--text);
}

.btn-undo:hover {
  background: var(--btn-bg);
  color: var(--text-light);
}

.btn-undo:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-undo:disabled:hover {
  background: var(--border-color);
  color: var(--text);
}

.btn-record-mid {
  background: var(--rank-gold);
  color: #3d2800;
}

.btn-record-mid:hover {
  background: #d4a800;
  color: #3d2800;
}

.btn-sound[data-on="false"] {
  opacity: 0.55;
}

.select-wrapper {
  position: relative;
}

.select-wrapper select {
  background: var(--score-bg);
  color: var(--text-light);
  border: none;
  border-radius: 8px;
  padding: 9px 30px 9px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background var(--transition);
}

.select-wrapper::after {
  content: '';
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid var(--text-light);
  opacity: 0.8;
}

.game-container {
  position: relative;
  background: var(--board-bg);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
  transition: background var(--transition);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

[data-theme="neon"] .game-container {
  box-shadow: 0 0 30px rgba(0, 229, 255, 0.15), 0 0 60px rgba(0, 229, 255, 0.05);
}

[data-theme="gold"] .game-container {
  box-shadow: 0 0 30px rgba(184, 134, 11, 0.2);
}

[data-theme="aurora"] .game-container {
  box-shadow: 0 0 30px rgba(0, 137, 123, 0.15);
}

.grid-container {
  display: grid;
  gap: 10px;
}

.grid-cell {
  background: var(--cell-bg);
  border-radius: 5px;
  aspect-ratio: 1;
}

.tile-container {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
}

.tile {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 900;
  border-radius: 5px;
  transition: top 0.1s ease, left 0.1s ease;
  z-index: 10;
}

.tile.new-tile {
  animation: pop-in 0.15s ease forwards;
}

.tile.merge-tile {
  animation: merge-pop 0.18s ease forwards;
}

@keyframes pop-in {
  0%   { transform: scale(0); }
  80%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes merge-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.tile-2    { background: #eee4da; color: #776e65; }
.tile-4    { background: #ede0c8; color: #776e65; }
.tile-8    { background: #f2b179; color: #fff; }
.tile-16   { background: #f59563; color: #fff; }
.tile-32   { background: #f67c5f; color: #fff; }
.tile-64   { background: #f65e3b; color: #fff; }
.tile-128  { background: #edcf72; color: #fff; }
.tile-256  { background: #edcc61; color: #fff; }
.tile-512  { background: #edc850; color: #fff; }
.tile-1024 { background: #edc53f; color: #fff; }
.tile-2048 { background: #edc22e; color: #fff; }
.tile-high { background: #3c3a32; color: #f9f6f2; }

[data-theme="dark"] .tile-2    { background: #3d3560; color: #e0d7cc; }
[data-theme="dark"] .tile-4    { background: #4a3d70; color: #e0d7cc; }
[data-theme="dark"] .tile-8    { background: #6c3483; color: #fff; }
[data-theme="dark"] .tile-16   { background: #7d3c98; color: #fff; }
[data-theme="dark"] .tile-32   { background: #8e44ad; color: #fff; }
[data-theme="dark"] .tile-64   { background: #9b59b6; color: #fff; }
[data-theme="dark"] .tile-128  { background: #a569bd; color: #fff; }
[data-theme="dark"] .tile-256  { background: #af7ac5; color: #fff; }
[data-theme="dark"] .tile-512  { background: #bb8fce; color: #fff; }
[data-theme="dark"] .tile-1024 { background: #c39bd3; color: #fff; }
[data-theme="dark"] .tile-2048 { background: #d7bde2; color: #1a1a2e; }
[data-theme="dark"] .tile-high { background: #ede0ff; color: #1a1a2e; }

[data-theme="forest"] .tile-2    { background: #2e7d32; color: #f1f8e9; }
[data-theme="forest"] .tile-4    { background: #388e3c; color: #f1f8e9; }
[data-theme="forest"] .tile-8    { background: #43a047; color: #fff; }
[data-theme="forest"] .tile-16   { background: #4caf50; color: #fff; }
[data-theme="forest"] .tile-32   { background: #66bb6a; color: #fff; }
[data-theme="forest"] .tile-64   { background: #81c784; color: #fff; }
[data-theme="forest"] .tile-128  { background: #a5d6a7; color: #1b2d1e; }
[data-theme="forest"] .tile-256  { background: #c8e6c9; color: #1b2d1e; }
[data-theme="forest"] .tile-512  { background: #dcedc8; color: #1b2d1e; }
[data-theme="forest"] .tile-1024 { background: #f1f8e9; color: #1b2d1e; }
[data-theme="forest"] .tile-2048 { background: #ffeb3b; color: #1b2d1e; }
[data-theme="forest"] .tile-high { background: #ffffff; color: #1b2d1e; }

[data-theme="ocean"] .tile-2    { background: #0d47a1; color: #e8f4fd; }
[data-theme="ocean"] .tile-4    { background: #1565c0; color: #e8f4fd; }
[data-theme="ocean"] .tile-8    { background: #1976d2; color: #fff; }
[data-theme="ocean"] .tile-16   { background: #1e88e5; color: #fff; }
[data-theme="ocean"] .tile-32   { background: #2196f3; color: #fff; }
[data-theme="ocean"] .tile-64   { background: #42a5f5; color: #fff; }
[data-theme="ocean"] .tile-128  { background: #64b5f6; color: #0d1b2a; }
[data-theme="ocean"] .tile-256  { background: #90caf9; color: #0d1b2a; }
[data-theme="ocean"] .tile-512  { background: #bbdefb; color: #0d1b2a; }
[data-theme="ocean"] .tile-1024 { background: #e3f2fd; color: #0d1b2a; }
[data-theme="ocean"] .tile-2048 { background: #fff9c4; color: #0d1b2a; }
[data-theme="ocean"] .tile-high { background: #ffffff; color: #0d1b2a; }

[data-theme="candy"] .tile-2    { background: #fce4ec; color: #c2185b; }
[data-theme="candy"] .tile-4    { background: #f8bbd0; color: #c2185b; }
[data-theme="candy"] .tile-8    { background: #f48fb1; color: #fff; }
[data-theme="candy"] .tile-16   { background: #f06292; color: #fff; }
[data-theme="candy"] .tile-32   { background: #ec407a; color: #fff; }
[data-theme="candy"] .tile-64   { background: #e91e63; color: #fff; }
[data-theme="candy"] .tile-128  { background: #c2185b; color: #fff; }
[data-theme="candy"] .tile-256  { background: #ad1457; color: #fff; }
[data-theme="candy"] .tile-512  { background: #880e4f; color: #fff; }
[data-theme="candy"] .tile-1024 { background: #ff80ab; color: #880e4f; }
[data-theme="candy"] .tile-2048 { background: #ffee58; color: #880e4f; }
[data-theme="candy"] .tile-high { background: #ffffff; color: #880e4f; }

[data-theme="sunset"] .tile-2    { background: #bf360c; color: #fff8f0; }
[data-theme="sunset"] .tile-4    { background: #d84315; color: #fff8f0; }
[data-theme="sunset"] .tile-8    { background: #e64a19; color: #fff; }
[data-theme="sunset"] .tile-16   { background: #f4511e; color: #fff; }
[data-theme="sunset"] .tile-32   { background: #ff5722; color: #fff; }
[data-theme="sunset"] .tile-64   { background: #ff7043; color: #fff; }
[data-theme="sunset"] .tile-128  { background: #ff8a65; color: #fff; }
[data-theme="sunset"] .tile-256  { background: #ffab91; color: #3e1800; }
[data-theme="sunset"] .tile-512  { background: #ffccbc; color: #3e1800; }
[data-theme="sunset"] .tile-1024 { background: #ffd180; color: #3e1800; }
[data-theme="sunset"] .tile-2048 { background: #ffe57f; color: #3e1800; }
[data-theme="sunset"] .tile-high { background: #ffffff; color: #3e1800; }

[data-theme="neon"] .tile-2    { background: #003333; color: #00e5ff; }
[data-theme="neon"] .tile-4    { background: #004d40; color: #00e5ff; }
[data-theme="neon"] .tile-8    { background: #006064; color: #00e5ff; }
[data-theme="neon"] .tile-16   { background: #00838f; color: #fff; }
[data-theme="neon"] .tile-32   { background: #0097a7; color: #fff; }
[data-theme="neon"] .tile-64   { background: #00acc1; color: #060612; }
[data-theme="neon"] .tile-128  { background: #00bcd4; color: #060612; }
[data-theme="neon"] .tile-256  { background: #00e5ff; color: #060612; }
[data-theme="neon"] .tile-512  { background: #40ffff; color: #060612; }
[data-theme="neon"] .tile-1024 { background: #80ffff; color: #060612; }
[data-theme="neon"] .tile-2048 { background: #e040fb; color: #fff; }
[data-theme="neon"] .tile-high { background: #ffffff; color: #060612; }

[data-theme="neon"] .tile-2048,
[data-theme="neon"] .tile-high {
  box-shadow: 0 0 16px currentColor;
}

[data-theme="ink"] .tile-2    { background: #ede0d0; color: #1a1208; }
[data-theme="ink"] .tile-4    { background: #d9c8b0; color: #1a1208; }
[data-theme="ink"] .tile-8    { background: #bfa882; color: #1a1208; }
[data-theme="ink"] .tile-16   { background: #a08060; color: #fff; }
[data-theme="ink"] .tile-32   { background: #806040; color: #fff; }
[data-theme="ink"] .tile-64   { background: #604020; color: #fff; }
[data-theme="ink"] .tile-128  { background: #402810; color: #fff; }
[data-theme="ink"] .tile-256  { background: #301a08; color: #fff; }
[data-theme="ink"] .tile-512  { background: #200e00; color: #ffd4a3; }
[data-theme="ink"] .tile-1024 { background: #8b2500; color: #fff; }
[data-theme="ink"] .tile-2048 { background: #cc0000; color: #fff; }
[data-theme="ink"] .tile-high { background: #000000; color: #ffd4a3; }

[data-theme="gold"] .tile-2    { background: #3d2d00; color: #ffd700; }
[data-theme="gold"] .tile-4    { background: #4a3800; color: #ffd700; }
[data-theme="gold"] .tile-8    { background: #5c4500; color: #ffd700; }
[data-theme="gold"] .tile-16   { background: #6e5200; color: #ffd700; }
[data-theme="gold"] .tile-32   { background: #806000; color: #ffd700; }
[data-theme="gold"] .tile-64   { background: #8b6914; color: #fff8dc; }
[data-theme="gold"] .tile-128  { background: #a07820; color: #fff; }
[data-theme="gold"] .tile-256  { background: #b8860b; color: #fff; }
[data-theme="gold"] .tile-512  { background: #d4a017; color: #1a1200; }
[data-theme="gold"] .tile-1024 { background: #e6b800; color: #1a1200; }
[data-theme="gold"] .tile-2048 { background: #ffd700; color: #1a1200; }
[data-theme="gold"] .tile-high { background: #fffacd; color: #1a1200; }

[data-theme="aurora"] .tile-2    { background: #004d40; color: #a8edea; }
[data-theme="aurora"] .tile-4    { background: #00695c; color: #a8edea; }
[data-theme="aurora"] .tile-8    { background: #00796b; color: #e0fffe; }
[data-theme="aurora"] .tile-16   { background: #00897b; color: #fff; }
[data-theme="aurora"] .tile-32   { background: #009688; color: #fff; }
[data-theme="aurora"] .tile-64   { background: #26a69a; color: #fff; }
[data-theme="aurora"] .tile-128  { background: #4db6ac; color: #0a1628; }
[data-theme="aurora"] .tile-256  { background: #80cbc4; color: #0a1628; }
[data-theme="aurora"] .tile-512  { background: #a8edea; color: #0a1628; }
[data-theme="aurora"] .tile-1024 { background: #7986cb; color: #fff; }
[data-theme="aurora"] .tile-2048 { background: #ce93d8; color: #0a1628; }
[data-theme="aurora"] .tile-high { background: #fff; color: #0a1628; }

.game-message {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  border-radius: 10px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  gap: 10px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.game-message.show {
  display: flex;
  animation: fade-in 0.3s ease;
}

.message-icon {
  width: 60px;
  height: 60px;
  color: var(--text);
  opacity: 0.85;
}

.message-icon svg {
  width: 100%;
  height: 100%;
}

.game-message p {
  font-size: 30px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.5px;
}

.message-sub {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  opacity: 0.65;
  margin-bottom: 4px;
}

.message-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.instructions {
  font-size: 14px;
  line-height: 1.7;
  opacity: 0.7;
  margin-bottom: 10px;
}

.instructions p + p {
  margin-top: 2px;
}

.copyright {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text);
  opacity: 0.5;
  line-height: 1.9;
}

.copyright a {
  color: inherit;
  text-decoration: underline;
}

.score-add-anim {
  position: fixed;
  font-size: 17px;
  font-weight: 900;
  color: var(--btn-bg);
  pointer-events: none;
  animation: score-float 0.85s ease forwards;
  z-index: 300;
}

@keyframes score-float {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-50px); }
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.show {
  display: flex;
  animation: fade-in 0.22s ease;
}

.modal {
  background: var(--modal-bg);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 20px 60px var(--modal-shadow);
  transition: background var(--transition);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-title {
  font-size: 20px;
  font-weight: 900;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-title-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  opacity: 0.5;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

.modal-close:hover {
  opacity: 1;
  background: var(--cell-bg);
}

.leaderboard-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--notice-bg);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  opacity: 0.75;
  margin-bottom: 14px;
}

.leaderboard-notice svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tab-btn {
  background: var(--cell-bg);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, opacity 0.2s;
  opacity: 0.6;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn.active {
  background: var(--btn-bg);
  color: var(--text-light);
  opacity: 1;
}

.leaderboard-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px;
  justify-content: center;
  color: var(--text);
  opacity: 0.6;
  font-size: 14px;
  font-weight: 700;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--border-color);
  border-top-color: var(--btn-bg);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.leaderboard-list {
  list-style: none;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--cell-bg);
  transition: background var(--transition);
}

.leaderboard-item:hover {
  background: var(--border-color);
}

.rank-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  flex-shrink: 0;
  background: var(--border-color);
  color: var(--text);
}

.rank-badge.gold   { background: var(--rank-gold);   color: #3d2800; }
.rank-badge.silver { background: var(--rank-silver);  color: #222; }
.rank-badge.bronze { background: var(--rank-bronze);  color: #fff; }

.leaderboard-info {
  flex: 1;
  min-width: 0;
}

.leaderboard-player-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-score {
  font-size: 17px;
  font-weight: 900;
  color: var(--text);
}

.leaderboard-meta {
  font-size: 11px;
  opacity: 0.55;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-size-badge {
  font-size: 11px;
  font-weight: 800;
  background: var(--border-color);
  color: var(--text);
  padding: 3px 7px;
  border-radius: 6px;
  opacity: 0.7;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 36px 20px;
  opacity: 0.45;
  font-size: 14px;
  font-weight: 700;
}

.custom-size-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group label {
  font-size: 13px;
  font-weight: 700;
  display: block;
  margin-bottom: 8px;
  opacity: 0.7;
}

.form-group input[type=range] {
  width: 100%;
  accent-color: var(--btn-bg);
  cursor: pointer;
  height: 4px;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  opacity: 0.5;
  margin-top: 5px;
  font-weight: 700;
}

.form-group input[type=number] {
  background: var(--cell-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 20px;
  font-weight: 900;
  color: var(--text);
  width: 100px;
  text-align: center;
  transition: border-color 0.2s;
}

.form-group input[type=number]:focus {
  outline: none;
  border-color: var(--btn-bg);
}

.size-display {
  font-size: 40px;
  font-weight: 900;
  text-align: center;
  color: var(--btn-bg);
  letter-spacing: -1px;
  padding: 8px 0 2px;
}

.record-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.record-score-section {
  text-align: center;
  padding: 16px 0;
}

.record-label {
  font-size: 13px;
  font-weight: 700;
  opacity: 0.7;
  margin-bottom: 6px;
}

.record-score-value {
  font-size: 42px;
  font-weight: 900;
  color: var(--btn-bg);
  letter-spacing: -1px;
  line-height: 1.1;
}

.record-size-info {
  font-size: 13px;
  font-weight: 700;
  opacity: 0.55;
  margin-top: 6px;
}

.record-username-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.record-username-hint {
  font-size: 12px;
  font-weight: 700;
  opacity: 0.5;
  color: var(--text);
}

.record-username-field {
  background: var(--cell-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  width: 100%;
  transition: border-color 0.2s;
}

.record-username-field:focus {
  outline: none;
  border-color: var(--btn-bg);
}

.record-username-field::placeholder {
  color: var(--text);
  opacity: 0.35;
}

.record-username-locked {
  background: var(--cell-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 16px;
  font-weight: 900;
  color: var(--btn-bg);
  width: 100%;
  opacity: 0.9;
}

.record-error {
  background: rgba(231, 76, 60, 0.12);
  border: 1px solid rgba(231, 76, 60, 0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #e74c3c;
  text-align: center;
}

.record-success {
  background: rgba(39, 174, 96, 0.12);
  border: 1px solid rgba(39, 174, 96, 0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #27ae60;
  text-align: center;
}

.record-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.record-actions .btn {
  flex: 1;
  justify-content: center;
  min-width: 120px;
}

@media (max-width: 520px) {
  body {
    padding: 10px;
  }

  h1 {
    font-size: 40px;
  }

  .score-box {
    min-width: 74px;
    padding: 7px 10px;
  }

  .score-value {
    font-size: 18px;
  }

  .toolbar-left {
    gap: 6px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  .btn-sm {
    padding: 6px 10px;
    font-size: 12px;
  }

  .game-container {
    padding: 8px;
    border-radius: 8px;
  }

  .grid-container {
    gap: 6px;
  }

  .tile-container {
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
  }

  .modal {
    padding: 18px;
    border-radius: 12px;
  }

  .game-message p {
    font-size: 22px;
  }

  .message-sub {
    font-size: 12px;
  }

  .size-display {
    font-size: 28px;
  }

  .theme-dot {
    width: 22px;
    height: 22px;
  }

  .message-icon {
    width: 48px;
    height: 48px;
  }

  .record-score-value {
    font-size: 32px;
  }

  .instructions {
    font-size: 12px;
  }
}

@media (max-width: 360px) {
  body {
    padding: 6px;
  }

  h1 {
    font-size: 32px;
  }

  .score-box {
    min-width: 62px;
    padding: 5px 8px;
  }

  .score-value {
    font-size: 16px;
  }

  .score-title {
    font-size: 10px;
  }

  .btn {
    padding: 7px 10px;
    font-size: 12px;
    gap: 4px;
  }

  .btn-sm {
    padding: 5px 8px;
    font-size: 11px;
  }

  .btn svg {
    width: 13px;
    height: 13px;
  }

  .game-container {
    padding: 6px;
  }

  .grid-container {
    gap: 4px;
  }

  .tile-container {
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: 6px;
  }

  .theme-dot {
    width: 20px;
    height: 20px;
  }

  .theme-bar {
    gap: 5px;
  }

  .modal {
    padding: 14px;
  }

  .modal-title {
    font-size: 17px;
  }

  .record-score-value {
    font-size: 28px;
  }
}
