:root {
  --surface: #0b1326;
  --surface-dim: #0b1326;
  --surface-bright: #31394d;
  --surface-container-lowest: #060e20;
  --surface-container-low: #131b2e;
  --surface-container: #171f33;
  --surface-container-high: #222a3d;
  --surface-container-highest: #2d3449;
  --on-surface: #dae2fd;
  --on-surface-variant: #c2c6d6;
  --primary: #adc6ff;
  --on-primary: #002e6a;
  --primary-container: #4d8eff;
  --on-primary-container: #00285d;
  --error: #ffb4ab;
  --on-error: #690005;
  --background: #020617; /* Level 0 floor */
  --nav-bg: #1e293b;

  --font-display: 'Manrope', 'Noto Sans KR', sans-serif;
  --font-body: 'Inter', 'Noto Sans KR', sans-serif;
  --font-mono: monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  background-color: var(--background);
  color: var(--on-surface);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Typography */
h1, h2, h3, .tile-number {
  font-family: var(--font-display);
}

/* Navigation */
.top-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  background-color: rgba(30, 41, 59, 0.85); /* nav-bg with blur */
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.nav-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--on-surface-variant);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  background-color: var(--surface-container-high);
  color: var(--on-surface);
}

.nav-btn.active {
  background-color: var(--surface-container-highest);
  color: var(--primary);
  border-color: rgba(255, 255, 255, 0.1);
}

.record-btn {
  background-color: var(--surface-container-low);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--on-surface);
}

/* Main Content */
#app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  width: 100%;
  margin: 0 auto;
}

.view {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* Game Setup for Custom */
#custom-setup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 auto 24px auto;
  flex-wrap: wrap;
  justify-content: center;
  width: max-content;
  max-width: 100%;
  background-color: var(--surface-container);
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.num-input {
  width: 60px;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid var(--surface-bright);
  background-color: var(--surface-container-lowest);
  color: var(--on-surface);
  font-family: var(--font-mono);
  text-align: center;
}

.divider {
  color: var(--surface-bright);
}

.btn-create {
  background: linear-gradient(180deg, #ff7a77 0%, var(--error) 100%);
  color: var(--on-error);
  border: none;
  padding: 8px 16px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Game Area */
.game-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0 auto;
  width: max-content;
  background-color: var(--surface-container-lowest);
  padding: 16px;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background-color: var(--surface-container);
  border-radius: 8px;
}

.status-chip {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: bold;
  background-color: var(--surface-container-lowest);
  padding: 8px 16px;
  border-radius: 12px;
  color: var(--on-surface);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  min-width: 120px;
  text-align: center;
}

.face-btn {
  font-size: 24px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  transition: transform 0.1s;
}

.face-btn:active {
  transform: scale(0.9);
}

.btn-pause {
  background-color: var(--surface-container-lowest);
  border: none;
  color: var(--on-surface);
  font-size: 16px;
  width: 40px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.btn-pause:hover {
  background-color: var(--surface-container-high);
}

.board-wrapper {
  display: flex;
  justify-content: center;
  position: relative;
}

.board-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(2, 6, 23, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--on-surface);
  font-size: 24px;
  font-weight: 700;
  border-radius: 8px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.board-wrapper.paused .board-overlay {
  opacity: 1;
  pointer-events: auto;
}

.game-board {
  display: grid;
  gap: 2px;
  background-color: var(--surface-container-lowest);
  padding: 4px;
  border-radius: 8px;
  touch-action: none; /* Prevent scroll while clicking */
}

/* Tiles */
.tile {
  width: 32px;
  height: 32px;
  background-color: var(--surface-container-highest);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  
  /* Unrevealed tile depth */
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.15), 0 2px 0px rgba(0, 0, 0, 0.5);
  transition: background-color 0.1s;
}

.tile:active {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
  transform: translateY(2px);
}

.tile.revealed {
  background-color: var(--surface-container-lowest);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  cursor: default;
  transform: none;
}

.tile.revealed.mine-hit {
  background-color: var(--error);
}

/* Custom tile colors for numbers */
.tile[data-val="1"] { color: #adc6ff; } /* primary */
.tile[data-val="2"] { color: #4edea3; } /* secondary */
.tile[data-val="3"] { color: #ffb3ad; } /* tertiary */
.tile[data-val="4"] { color: #cda2ff; }
.tile[data-val="5"] { color: #ffa970; }
.tile[data-val="6"] { color: #5ce6e6; }
.tile[data-val="7"] { color: #ff85c2; }
.tile[data-val="8"] { color: #e6e6e6; }

/* Buttons */
.action-bar {
  margin: 24px auto 0 auto;
  width: max-content;
  display: flex;
  gap: 16px;
  justify-content: flex-end;
}
.action-bar.centered {
  justify-content: center;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(180deg, var(--primary-container) 0%, #1a66ff 100%);
  color: var(--on-primary-container);
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
  transition: opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 12px 24px;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-secondary:hover {
  background-color: rgba(173, 198, 255, 0.1);
}

/* Records View */
.records-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  width: 100%;
}

.record-panel {
  background: var(--surface-container);
  border-radius: 12px;
  padding: 24px;
  min-height: 400px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.record-panel h3 {
  text-align: center;
  margin-bottom: 24px;
  color: var(--primary);
}

.record-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record-item {
  background: var(--surface-container-high);
  padding: 12px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

@media (max-width: 768px) {
  .top-nav {
    flex-direction: column;
    align-items: stretch;
  }
  .nav-left {
    justify-content: center;
  }
  .nav-right {
    display: flex;
    justify-content: center;
  }
  .tile {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
}
