/* ============================================================================
   CZARNE I BIAŁE PERŁY (MASYU) - STYLESHEET
   Themes: Ocean Abyss, Black Velvet, Sakura Pearl, Sumi-e Ink
   ============================================================================ */

:root {
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: 'Cinzel', serif, Georgia;
  --font-mono: 'Fira Code', monospace;

  /* Theme: Ocean Abyss (Default) */
  --bg-app: #071322;
  --bg-gradient: radial-gradient(circle at 50% 25%, #0e2949 0%, #040c17 100%);
  --bg-card: rgba(12, 34, 58, 0.88);
  --bg-card-border: rgba(56, 189, 248, 0.25);
  --text-main: #f0f9ff;
  --text-muted: #7dd3fc;
  --accent-gold: #f59e0b;
  --accent-emerald: #10b981;
  --accent-crimson: #ef4444;

  /* Board & Grid */
  --board-bg: #081a2f;
  --cell-bg: rgba(14, 41, 71, 0.5);
  --cell-border: rgba(56, 189, 248, 0.18);
  --cell-hover: rgba(56, 189, 248, 0.12);

  /* Loop Lines */
  --line-core: #fbbf24;
  --line-outer: #b45309;
  --line-glow: rgba(245, 158, 11, 0.5);
  --cross-color: #ef4444;

  /* Pearls */
  --pearl-white-outer: #ffffff;
  --pearl-white-inner: #cbd5e1;
  --pearl-white-border: #94a3b8;

  --pearl-black-outer: #0f172a;
  --pearl-black-inner: #020617;
  --pearl-black-border: #475569;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* ============================================================================
   THEMES
   ============================================================================ */

/* 2. Black Velvet (Luxury Jewelry Display) */
body.theme-velvet {
  --bg-app: #08090d;
  --bg-gradient: radial-gradient(circle at 50% 25%, #161822 0%, #050608 100%);
  --bg-card: rgba(22, 24, 35, 0.9);
  --bg-card-border: rgba(165, 180, 252, 0.22);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --board-bg: #0d0f17;
  --cell-bg: rgba(25, 28, 42, 0.5);
  --cell-border: rgba(148, 163, 184, 0.16);
  --line-core: #38bdf8;
  --line-outer: #0284c7;
  --line-glow: rgba(56, 189, 248, 0.5);
  --accent-gold: #38bdf8;
}

/* 3. Sakura Pearl (Cherry Blossom Rose Quartz) */
body.theme-sakura {
  --bg-app: #1d111a;
  --bg-gradient: radial-gradient(circle at 50% 25%, #351a2c 0%, #120a10 100%);
  --bg-card: rgba(48, 24, 40, 0.88);
  --bg-card-border: rgba(244, 114, 182, 0.25);
  --text-main: #fdf2f8;
  --text-muted: #f472b6;
  --board-bg: #22121e;
  --cell-bg: rgba(56, 28, 48, 0.45);
  --cell-border: rgba(244, 114, 182, 0.18);
  --line-core: #fb7185;
  --line-outer: #be123c;
  --line-glow: rgba(251, 113, 133, 0.5);
  --accent-gold: #f472b6;
}

/* 4. Sumi-e Ink (Traditional Rice Paper) */
body.theme-ink {
  --bg-app: #f4efe6;
  --bg-gradient: radial-gradient(circle at 50% 25%, #fdfaf4 0%, #e6decb 100%);
  --bg-card: rgba(255, 255, 255, 0.94);
  --bg-card-border: rgba(40, 30, 20, 0.18);
  --text-main: #1f1b18;
  --text-muted: #786d63;
  --board-bg: #faf7f0;
  --cell-bg: #ffffff;
  --cell-border: rgba(40, 30, 20, 0.14);
  --line-core: #18181b;
  --line-outer: #3f3f46;
  --line-glow: transparent;
  --accent-gold: #c2410c;
  --pearl-white-outer: #ffffff;
  --pearl-white-inner: #f1f5f9;
  --pearl-white-border: #18181b;
  --pearl-black-outer: #18181b;
  --pearl-black-inner: #09090b;
  --pearl-black-border: #18181b;
}

/* ============================================================================
   RESET & BASE LAYOUT
   ============================================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font-main);
  background: var(--bg-gradient);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
}

.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-height: 100vh;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px 16px;
}

@media (max-height: 720px) {
  .app-wrapper {
    max-height: none;
    min-height: 100vh;
  }
}

/* ============================================================================
   HEADER & NAVIGATION
   ============================================================================ */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(56, 189, 248, 0.2));
  border: 1px solid var(--bg-card-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.brand-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 1.1;
  background: linear-gradient(135deg, #ffffff 40%, var(--text-muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

body.theme-ink .brand-title {
  background: none;
  -webkit-text-fill-color: var(--text-main);
}

.brand-subtitle {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

.controls-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.select-diff {
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-main);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
}

body.theme-ink .select-diff {
  background: #ffffff;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Tool Toggles (Line vs Cross) */
.tool-group {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.btn-tool {
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-tool.active {
  background: var(--accent-gold);
  color: #000000;
  font-weight: 700;
}

/* Common Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  outline: none;
}

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

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--bg-card-border);
}

body.theme-ink .btn-secondary {
  background: #f0eae1;
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--bg-card-border);
  color: var(--text-main);
}

.btn-icon:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}

/* ============================================================================
   INFO BAR
   ============================================================================ */

.info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  font-size: 0.92rem;
  gap: 12px;
  flex-wrap: wrap;
}

.info-left, .info-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stage-badge {
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.pearl-counter-badge {
  font-size: 0.84rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  transition: all 0.3s ease;
}

.pearl-counter-badge.all-done {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}

.timer-wrapper {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-gold);
  background: rgba(0, 0, 0, 0.3);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
}

body.theme-ink .timer-wrapper {
  background: #eae3d5;
  color: #1a1614;
}

/* ============================================================================
   BOARD PLAYFIELD (SVG CANVAS CONTAINER)
   ============================================================================ */

.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.board-container {
  flex: 1;
  min-height: 360px;
  max-height: calc(100vh - 230px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--board-bg);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 4px 25px rgba(0, 0, 0, 0.4), var(--shadow-card);
  position: relative;
  overflow: hidden;
  padding: 10px;
  touch-action: none;
}

.board-svg {
  width: 100%;
  height: 100%;
  max-width: 660px;
  max-height: 660px;
  display: block;
}

/* ============================================================================
   SVG ELEMENTS
   ============================================================================ */

/* Grid Cells */
.grid-cell {
  fill: var(--cell-bg);
  stroke: var(--cell-border);
  stroke-width: 1;
  transition: fill 0.15s ease;
  cursor: crosshair;
}

.grid-cell:hover {
  fill: var(--cell-hover);
}

.grid-cell.cell-highlight {
  fill: rgba(245, 158, 11, 0.25) !important;
  stroke: var(--accent-gold) !important;
  stroke-width: 2 !important;
}

/* Loop Lines */
.loop-line-outer {
  stroke: var(--line-outer);
  stroke-width: 8;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--line-glow));
  pointer-events: none;
}

.loop-line-core {
  stroke: var(--line-core);
  stroke-width: 4.5;
  stroke-linecap: round;
  pointer-events: none;
}

.loop-joint {
  fill: var(--line-core);
  pointer-events: none;
}

/* Cross Markers (X) */
.cross-line {
  stroke: var(--cross-color);
  stroke-width: 2.5;
  stroke-linecap: round;
  pointer-events: none;
}

/* Pearls (Anchored, Stable, NO CSS transform scales!) */
.pearl-node {
  pointer-events: none; /* Pointer events pass through to grid cells for smooth dragging */
}

.pearl-halo {
  fill: transparent;
  stroke: transparent;
  stroke-width: 3.5;
  transition: stroke 0.25s ease, opacity 0.25s ease;
}

.pearl-node.satisfied .pearl-halo {
  stroke: var(--accent-emerald);
  opacity: 0.85;
}

.pearl-node.error .pearl-halo {
  stroke: var(--accent-crimson);
  opacity: 0.95;
  stroke-width: 4.5;
  animation: pearl-alert 1s ease-in-out infinite;
}

@keyframes pearl-alert {
  0%, 100% { opacity: 0.95; stroke-width: 4.5; }
  50% { opacity: 0.4; stroke-width: 7; }
}

/* White Pearl Styling */
.pearl-white .pearl-body {
  fill: var(--pearl-white-outer);
  stroke: var(--pearl-white-border);
  stroke-width: 2.5;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

.pearl-white .pearl-specular {
  fill: rgba(255, 255, 255, 0.7);
}

/* Black Pearl Styling */
.pearl-black .pearl-body {
  fill: var(--pearl-black-outer);
  stroke: var(--pearl-black-border);
  stroke-width: 2.5;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.6));
}

.pearl-black .pearl-specular {
  fill: rgba(255, 255, 255, 0.45);
}

/* Status Badges */
.satisfied-badge {
  fill: var(--accent-emerald);
  stroke: var(--board-bg);
  stroke-width: 1.5;
}

.error-badge {
  fill: var(--accent-crimson);
  stroke: var(--board-bg);
  stroke-width: 1.5;
}

/* ============================================================================
   STATUS BANNER & HINT TOAST
   ============================================================================ */

.status-banner {
  margin-top: 12px;
  padding: 12px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  text-align: center;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  box-shadow: var(--shadow-card);
  transition: all 0.3s ease;
}

.status-banner.active {
  color: var(--accent-gold);
  border-color: rgba(245, 158, 11, 0.4);
}

.status-banner.warning {
  color: var(--accent-crimson);
  border-color: rgba(239, 68, 68, 0.4);
}

.status-banner.solved {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(5, 150, 105, 0.25));
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.6);
}

.hint-toast {
  position: absolute;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--accent-gold);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  max-width: 520px;
  width: 90%;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: slide-up 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.hint-toast.hidden {
  display: none;
}

.hint-content {
  flex: 1;
}

.hint-title {
  font-weight: 700;
  color: var(--accent-gold);
  font-size: 0.96rem;
  margin-bottom: 4px;
}

.hint-msg {
  font-size: 0.88rem;
  color: var(--text-main);
  line-height: 1.4;
}

.btn-close-toast {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 6px;
}

@keyframes slide-up {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ============================================================================
   MODALS (Rules, Stats, Levels, Win)
   ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bg-card-border);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px 24px;
  line-height: 1.6;
  font-size: 0.95rem;
}

.modal-body h3 {
  color: var(--accent-gold);
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body ul {
  padding-left: 20px;
  margin-bottom: 14px;
}

.modal-body li {
  margin-bottom: 8px;
}

/* Victory Modal */
.win-card {
  text-align: center;
  padding: 32px 24px;
  max-width: 480px;
}

.win-icon {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: bounce-trophy 1.2s ease infinite;
}

@keyframes bounce-trophy {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.win-title {
  font-size: 1.55rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: #34d399;
  margin-bottom: 6px;
}

.win-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.win-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.win-stat-box {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
}

.win-stat-val {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.win-stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

/* Level Selection Grid */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.level-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.level-card:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-2px);
  border-color: var(--accent-gold);
}

.level-card.active {
  border-color: var(--accent-emerald);
  background: rgba(16, 185, 129, 0.15);
}

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

.level-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.level-diff-badge {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
}

.level-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Stats Modal Grid */
.stats-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stats-times-list {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.time-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.9rem;
}

.time-row:last-child {
  border-bottom: none;
}

.time-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-gold);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
  }
  .controls-center, .header-right {
    justify-content: center;
  }
  .board-container {
    min-height: 380px;
  }
}

/* Link powrotu do listy gier (integracja z serwisem). */
.brand-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border-color, #cbd5e1);
  border-radius: 8px;
  color: var(--accent-blue, #1d4ed8);
  background: rgba(29, 78, 216, 0.08);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.brand-back:hover {
  background: rgba(29, 78, 216, 0.16);
}
