/* ==========================================================================
   YIN-YANG MASTER (陰陽黑白解謎網) - Modern Design System
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Noto+Sans+TC:wght@400;500;600;700;900&display=swap');

:root {
  /* Color Tokens - Light Mode Default */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-solid: #ffffff;
  --bg-elevated: #f1f5f9;
  --border-subtle: #e2e8f0;
  --border-glass: rgba(226, 232, 240, 0.8);
  --border-strong: #cbd5e1;

  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-glow: rgba(79, 70, 229, 0.25);

  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-emerald-light: #ecfdf5;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-rose-light: #fff1f2;

  /* Stone Tokens */
  --stone-black-bg: radial-gradient(circle at 35% 35%, #475569 0%, #1e293b 45%, #090d16 100%);
  --stone-black-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 2px 3px rgba(255, 255, 255, 0.3);
  --stone-white-bg: radial-gradient(circle at 35% 35%, #ffffff 0%, #f1f5f9 60%, #cbd5e1 100%);
  --stone-white-border: #94a3b8;
  --stone-white-shadow: 0 4px 10px rgba(0, 0, 0, 0.15), inset 0 -2px 4px rgba(0, 0, 0, 0.1);

  /* Grid tokens */
  --grid-line: #cbd5e1;
  --grid-bg: #ffffff;
  --grid-cell-hover: #f1f5f9;
  --cell-size: 52px;

  /* Elevation */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 6px 20px -4px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 36px -8px rgba(0, 0, 0, 0.12);
  --transition-fast: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Outfit', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 12% 15%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 88% 30%, rgba(6, 182, 212, 0.07) 0%, transparent 40%),
    radial-gradient(circle at 50% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
  background-attachment: fixed;
  transition: background-color var(--transition-smooth), color var(--transition-smooth);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-glass);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: conic-gradient(#ffffff 0deg 180deg, #0f172a 180deg 360deg);
  border: 2px solid var(--border-strong);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.brand-icon::before {
  content: '';
  position: absolute;
  top: 0;
  left: 25%;
  width: 50%;
  height: 50%;
  border-radius: 50%;
  background: #0f172a;
}

.brand-icon::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 25%;
  width: 50%;
  height: 50%;
  border-radius: 50%;
  background: #ffffff;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: flex;
  flex-direction: column;
}

.brand-title span.sub {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  align-items: center;
  background: var(--bg-elevated);
  padding: 4px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  gap: 4px;
}

.tab-btn {
  padding: 8px 18px;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.05rem;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-surface);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

/* Main Container */
.main-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

/* Tab Views */
.tab-content {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   GAME VIEW (線上挑戰)
   ========================================================================== */
.game-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 28px;
  align-items: start;
}

@media (max-width: 960px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
}

/* Left Board Card */
.board-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 24px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Status Bar */
.game-status-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 18px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.status-pills {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.badge-tag.highlight {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.timer-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--bg-elevated);
  padding: 6px 16px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
}

/* Board Outer Container */
.board-outer {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  max-width: 100%;
  overflow-x: auto;
}

/* The Yin-Yang Grid */
.yinyang-grid {
  display: grid;
  background-color: var(--grid-line);
  padding: 3px;
  border-radius: var(--radius-md);
  gap: 2px;
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--border-strong);
  user-select: none;
  touch-action: manipulation;
}

/* Cell */
.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-color: var(--grid-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.grid-cell:hover:not(.clue) {
  background-color: var(--grid-cell-hover);
}

.grid-cell.focused {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  z-index: 2;
}

.grid-cell.clue {
  cursor: default;
}

.grid-cell.clue::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: var(--accent-amber);
  opacity: 0.75;
}

/* Cell 2x2 Conflict Alert Highlight */
.grid-cell.in-conflict {
  background-color: var(--accent-rose-light) !important;
  animation: pulseConflict 1.5s infinite;
}

@keyframes pulseConflict {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--accent-rose); }
  50% { box-shadow: inset 0 0 0 4px var(--accent-rose); }
}

/* Cell Stone Elements */
.stone {
  width: calc(var(--cell-size) * 0.76);
  height: calc(var(--cell-size) * 0.76);
  border-radius: 50%;
  position: relative;
  transition: transform 0.15s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.15s;
  animation: dropStone 0.18s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes dropStone {
  0% { transform: scale(0.65); opacity: 0.3; }
  100% { transform: scale(1); opacity: 1; }
}

.stone.black {
  background: var(--stone-black-bg);
  box-shadow: var(--stone-black-shadow);
}

.stone.white {
  background: var(--stone-white-bg);
  box-shadow: var(--stone-white-shadow);
  border: 1px solid var(--stone-white-border);
}

/* Clue Stone Anchor ring */
.grid-cell.clue .stone {
  box-shadow: 0 0 0 2.5px var(--primary), var(--stone-black-shadow);
}
.grid-cell.clue .stone.white {
  box-shadow: 0 0 0 2.5px var(--primary), var(--stone-white-shadow);
}

/* Action Toolbar Below Board */
.board-toolbar {
  width: 100%;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Brush Mode Selector */
.brush-selector {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  padding: 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.brush-btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.92rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.brush-btn .mini-stone {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
}

.mini-stone.black {
  background: #0f172a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.mini-stone.white {
  background: #ffffff;
  border: 1px solid #94a3b8;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.brush-btn:hover {
  background: var(--bg-surface);
  color: var(--text-main);
}

.brush-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Primary Action Buttons */
.board-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-action {
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.btn-action:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.btn-action:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-action.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-action.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  filter: brightness(1.05);
}

/* Right Control Panel */
.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 24px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel-section-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--text-main);
}

/* Level Grid */
.level-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.level-row {
  display: flex;
  gap: 8px;
}

.btn-level {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
}

.btn-level:hover {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.btn-level.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* Settings Switches */
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.setting-item:last-child {
  border-bottom: none;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--border-strong);
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 9999px;
}

.slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider::before {
  transform: translateX(20px);
}

/* Hint Card Banner */
.hint-banner {
  background: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: none;
  animation: fadeIn 0.2s ease-out;
}

.hint-banner.show {
  display: block;
}

.hint-header {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.hint-body {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-main);
}

/* ==========================================================================
   PRINT VIEW (列印中心)
   ========================================================================== */
.print-config-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-md);
  margin-bottom: 28px;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.config-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.config-group label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.select-control {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.select-control:focus {
  border-color: var(--primary);
}

.print-preview-container {
  background: #525659;
  padding: 32px 16px;
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  min-height: 500px;
}

.paper-sheet {
  background: #ffffff;
  color: #000000;
  width: 210mm;
  min-height: 297mm;
  padding: 15mm 15mm;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  position: relative;
}

.paper-header {
  border-bottom: 2px solid #000000;
  padding-bottom: 8px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.paper-header h2 {
  font-size: 18pt;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.paper-header .paper-meta {
  font-size: 9pt;
  color: #444444;
}

.puzzles-print-grid {
  flex: 1;
  display: grid;
  gap: 20px;
  align-content: space-around;
}

.puzzles-print-grid.grid-1 {
  grid-template-columns: 1fr;
}
.puzzles-print-grid.grid-2 {
  grid-template-columns: 1fr 1fr;
}
.puzzles-print-grid.grid-4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.puzzles-print-grid.grid-6 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.print-puzzle-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px dashed #cccccc;
  padding: 12px;
  border-radius: 6px;
}

.print-puzzle-header {
  font-size: 11pt;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.paper-footer {
  border-top: 1px solid #cccccc;
  padding-top: 6px;
  margin-top: 16px;
  font-size: 8pt;
  color: #666666;
  text-align: center;
}

/* ==========================================================================
   GUIDE VIEW (規則與技巧)
   ========================================================================== */
.guide-container {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.guide-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

.guide-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.guide-card p {
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.7;
  margin-bottom: 16px;
}

.rule-highlight-box {
  background: var(--bg-elevated);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 16px 20px;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rule-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.rule-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
  flex-shrink: 0;
}

.rule-text {
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.5;
}

.lemma-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 16px;
  border: 1px solid var(--border-subtle);
}

.lemma-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.show {
  display: flex;
}

.modal-card {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  max-width: 440px;
  width: 100%;
  padding: 32px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-glass);
}

.modal-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
  animation: bounce 0.6s infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-item {
  background: var(--bg-elevated);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.stat-val {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-lbl {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Print CSS */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt;
  }

  .no-print,
  .app-header,
  .print-config-card,
  .header-actions,
  .brand-wrap,
  .nav-tabs,
  .board-toolbar,
  .panel-card,
  footer {
    display: none !important;
  }

  .main-wrapper {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }

  #section-print {
    display: block !important;
  }

  .print-preview-container {
    background: transparent !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  .paper-sheet {
    box-shadow: none !important;
    padding: 10mm !important;
    width: 100% !important;
    min-height: auto !important;
    page-break-after: always;
  }

  .paper-sheet:last-child {
    page-break-after: avoid;
  }
}

/* Responsive */
@media (max-width: 640px) {
  :root {
    --cell-size: 44px;
  }

  .header-inner {
    padding: 10px 14px;
  }

  .brand-title span.main-title {
    font-size: 1.05rem;
  }

  .nav-tabs {
    padding: 2px;
  }

  .tab-btn {
    padding: 6px 12px;
    font-size: 0.82rem;
  }

  .board-card {
    padding: 16px 12px;
  }

  .brush-btn {
    padding: 8px 10px;
    font-size: 0.82rem;
  }
}

/* ==========================================================================
   ARCADE & LOGIC GAMES COLLECTION (益智遊戲大廳 - 現代化優化排版)
   ========================================================================== */
.arcade-section {
  margin-top: 48px;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 32px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-smooth);
}

.arcade-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.arcade-title-group h2 {
  font-size: 1.45rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.arcade-title-group p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.arcade-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.arcade-search-box {
  position: relative;
  min-width: 240px;
}

.arcade-search-input {
  width: 100%;
  padding: 10px 16px 10px 38px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
  transition: all var(--transition-fast);
}

.arcade-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.arcade-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.88rem;
  pointer-events: none;
}

.btn-toggle-arcade {
  padding: 9px 16px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.btn-toggle-arcade:hover {
  background: var(--bg-surface);
  color: var(--primary);
  border-color: var(--primary);
}

/* Category Filter Chips */
.arcade-filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 24px;
  scrollbar-width: none;
}

.arcade-filter-bar::-webkit-scrollbar {
  display: none;
}

.arcade-filter-chip {
  padding: 7px 16px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.arcade-filter-chip:hover {
  color: var(--text-main);
  border-color: var(--border-strong);
}

.arcade-filter-chip.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* Games Grid */
.arcade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 18px;
  transition: all var(--transition-smooth);
}

.arcade-grid.collapsed {
  display: none;
}

/* Modern Game Card */
.arcade-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}

.arcade-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md), 0 0 16px var(--primary-glow);
}

/* Card Top Tags */
.card-top-tags {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

.card-cat-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-badge {
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.68rem;
  font-weight: 700;
  color: #ffffff;
}

/* Card Visual Vector Box */
.card-visual-box {
  width: 100px;
  height: 100px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  transition: transform var(--transition-fast);
}

.arcade-card:hover .card-visual-box {
  transform: scale(1.06);
}

/* Card Titles */
.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Card Action Button */
.card-btn {
  width: 100%;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.arcade-card:hover .card-btn {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Game Rule Preview Modal */
.game-rule-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.game-rule-modal.show {
  display: flex;
}

.game-rule-dialog {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  max-width: 520px;
  width: 100%;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-glass);
  animation: fadeIn 0.2s ease-out;
  position: relative;
}

.btn-close-dialog {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close-dialog:hover {
  color: var(--text-main);
  background: var(--bg-surface);
}


/* Reviewed arcade controls and rule-specific boards. */
.arcade-mode.active { background:var(--primary); color:#fff; }
#sudokuKeypad { display:flex; flex-wrap:wrap; gap:4px; justify-content:center; }
#sudokuKeypad button { min-width:32px; padding:6px; }
.sudoku-board { gap:0; border-radius:4px; }
.sudoku-board .grid-cell { width:clamp(28px,7.5vw,44px); height:clamp(28px,7.5vw,44px); }
.sudoku-board .grid-cell:focus { outline:2px solid var(--primary);outline-offset:-2px; }
.nonogram-clues { position:absolute; inset:0; pointer-events:none; }
.nonogram-col-clues { position:absolute;left:calc(50% + 35px);transform:translateX(-50%);top:16px;display:grid;align-items:end;height:78px;padding:0 3px; }
.nonogram-row-clues { position:absolute;left:calc(50% - 100px - 3.5 * (var(--cell-size) + 2px) + (var(--cell-size) + 2px));top:99px;display:grid;grid-auto-rows:calc(var(--cell-size) + 2px);width:64px; }
.nonogram-clue { pointer-events:auto;border:0;background:transparent;color:var(--text-main);font:700 1rem inherit;cursor:pointer;line-height:1.35; }
.nonogram-row-clues .nonogram-clue { text-align:right; padding-right:8px; }
.nonogram-clue.done { opacity:.45;text-decoration:line-through; }
.slitherlink-board { display:grid;width:min(420px,82vw);height:min(420px,82vw);gap:0;padding:12px;background:var(--grid-bg);border-radius:8px; }
.loop-dot,.loop-clue { display:flex;align-items:center;justify-content:center;color:var(--text-main);font-weight:700; }
.loop-dot::after { content:'';width:6px;height:6px;background:var(--text-main);border-radius:50%; }
.loop-clue { font-size:1.3rem; }
.loop-edge { position:relative;min-width:0;min-height:0;padding:0;border:0;background:transparent;cursor:pointer;color:var(--accent-rose);font-size:1.5rem; }
.loop-edge::after { content:'';position:absolute;background:var(--border-subtle);border-radius:3px; }
.loop-edge.h::after { height:3px;width:100%;left:0;top:calc(50% - 1.5px); }
.loop-edge.v::after { width:3px;height:100%;top:0;left:calc(50% - 1.5px); }
.loop-edge.drawn::after { background:var(--primary); }
.loop-edge.h.drawn::after { height:6px;top:calc(50% - 3px);width:200%;left:-50%; }
.loop-edge.v.drawn::after { width:6px;left:calc(50% - 3px);height:200%;top:-50%; }
.loop-edge.excluded::after { display:none; }
.loop-edge:focus-visible { outline:2px solid var(--primary); }

.nonogram-board-wrap { position:relative;flex-shrink:0;padding:80px 0 0 70px; }
.nonogram-board-wrap .nonogram-col-clues { left:73px;transform:none;top:0;height:78px;padding:0; }
.nonogram-board-wrap .nonogram-row-clues { left:0;top:83px;width:68px; }
.game-layout { grid-template-columns:minmax(0,1fr) 340px; }
.board-card { min-width:0; }
@media (max-width:960px) { .game-layout { grid-template-columns:minmax(0,1fr); } }
@media (max-width:640px) {
  .header-inner { flex-wrap:wrap;gap:10px; }
  .brand-wrap { flex:1 1 180px; }
  .header-actions { flex-wrap:wrap;justify-content:flex-end; }
  .nav-tabs { order:3;max-width:100%;overflow-x:auto; }
  .nav-tabs .tab-btn { flex-shrink:0; }
  .main-wrapper { padding:16px 10px; }
  .status-pills { flex-wrap:wrap;min-width:0; }
  .badge-tag { white-space:normal; }
  .board-outer { padding:12px 2px;justify-content:safe center; }
  .nonogram-board-wrap { --cell-size:clamp(30px,calc((100vw - 150px) / 5),56px); }
  .sudoku-board .grid-cell { width:clamp(26px,calc((100vw - 56px) / 9),44px);height:clamp(26px,calc((100vw - 56px) / 9),44px); }
  .slitherlink-board { width:min(420px,calc(100vw - 64px));height:min(420px,calc(100vw - 64px)); }
}

/* Multi-size Nonograms: clue tracks and cells share one measured grid pitch. */
.board-outer.nonogram-viewport { justify-content:flex-start; }
.nonogram-board-wrap {
  --cell-size:clamp(28px,calc((100vw - var(--nonogram-left) - 64px) / var(--nonogram-size) - 2px),var(--nonogram-max-cell));
  padding:var(--nonogram-top) 0 0 var(--nonogram-left);margin-inline:auto;
}
.nonogram-board-wrap .nonogram-col-clues { left:calc(var(--nonogram-left) + 3px);top:0;height:calc(var(--nonogram-top) - 2px); }
.nonogram-board-wrap .nonogram-row-clues { left:0;top:calc(var(--nonogram-top) + 3px);width:calc(var(--nonogram-left) - 2px); }
.nonogram-clue { font-family:inherit;font-weight:700;font-size:15px;line-height:21px;white-space:nowrap; }
.nonogram-board-wrap:not([data-size="4"]) .nonogram-grid .grid-cell:nth-child(5n) { border-right:2px solid var(--border-strong)!important; }
.nonogram-library-info { font-size:.85rem;color:var(--text-muted);margin:6px 0 12px; }

/* Larger loop boards keep tappable edge controls rather than shrinking every cell. */
.board-outer.slitherlink-viewport { justify-content:flex-start; }
.slitherlink-board { width:var(--loop-board-width);height:var(--loop-board-height);flex-shrink:0;margin-inline:auto; }

.board-outer.slitherlink-viewport { align-items:flex-start; max-height:min(70vh,720px); overflow:auto; }
#arcadeSidebarPanel label[for="slitherlinkSizeSelect"], #arcadeSidebarPanel label[for="slitherlinkDifficultySelect"] { display:block; margin:0 0 6px; } #slitherlinkSizeSelect, #slitherlinkDifficultySelect { width:100%; margin-bottom:12px; }
