/* ===========================================================
   Genshin Puzzle — pale, pinkish, calm theme
   =========================================================== */

:root {
  --bg-1: #fff5f8;
  --bg-2: #ffe9f0;
  --bg-3: #fde4ee;
  --card: #fff7fa;
  --card-2: #fff0f5;
  --ink: #6b4a57;
  --ink-soft: #9a7483;
  --ink-faint: #c39fad;
  --accent: #f4a6c4;
  --accent-2: #ef8db4;
  --accent-deep: #d76ea1;
  --line: #f3d3e0;
  --line-soft: #f8e3ec;
  --shadow: 0 12px 36px rgba(214, 110, 161, 0.18);
  --shadow-soft: 0 6px 18px rgba(214, 110, 161, 0.12);
  --radius: 22px;
  --radius-sm: 14px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Quicksand",
    "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 120% at 15% 10%, var(--bg-1) 0%, transparent 60%),
    radial-gradient(120% 120% at 85% 20%, var(--bg-2) 0%, transparent 55%),
    radial-gradient(140% 140% at 50% 100%, var(--bg-3) 0%, transparent 70%),
    var(--bg-1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Main container ---------- */
.container {
  width: min(1040px, 96vw);
  height: min(94vh, 920px);
  min-height: 540px;
  background: linear-gradient(160deg, var(--card) 0%, var(--card-2) 100%);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ---------- Persistent header ---------- */
#header {
  flex: 0 0 auto;
  padding: 22px 28px 18px;
  text-align: center;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255,255,255,0.55), rgba(255,255,255,0));
}

.title {
  font-size: clamp(1.6rem, 3.4vw, 2.3rem);
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--accent-deep);
  text-shadow: 0 2px 8px rgba(215, 110, 161, 0.14);
}

.subtitle {
  margin-top: 4px;
  font-size: clamp(0.85rem, 1.8vw, 1rem);
  color: var(--ink-soft);
  letter-spacing: 0.4px;
}

/* ---------- Content / screens ---------- */
#content {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  border-radius: 0 0 var(--radius) var(--radius);
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 22px 26px;
  transition: opacity 0.45s var(--ease), transform 0.45s var(--ease);
}

.screen.hidden {
  display: none;
}

.screen-center {
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* fade-in helper for screen swaps */
.screen.fade-in {
  animation: fadeIn 0.5s var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Buttons ---------- */
.big-btn {
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-2) 100%);
  border: none;
  border-radius: 999px;
  padding: 16px 42px;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(239, 141, 180, 0.4);
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), filter 0.25s var(--ease);
}
.big-btn:hover { transform: translateY(-2px); filter: brightness(1.04); box-shadow: 0 14px 32px rgba(239, 141, 180, 0.5); }
.big-btn:active { transform: translateY(0); }

.small-btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-deep);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  transition: all 0.25s var(--ease);
}
.small-btn:hover { background: var(--bg-2); border-color: var(--accent); transform: translateY(-1px); }

.ctrl-btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}
.ctrl-btn:hover { background: var(--bg-2); border-color: var(--accent); color: var(--accent-deep); }
.ctrl-btn.primary {
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 16px rgba(239, 141, 180, 0.35);
}
.ctrl-btn.primary:hover { filter: brightness(1.05); }
.ctrl-btn.active {
  background: var(--accent-2);
  color: #fff;
  border-color: transparent;
}

/* ---------- State 2: list ---------- */
.list-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: 0 0 auto;
}

.search-bar {
  flex: 1 1 auto;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  outline: none;
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.search-bar::placeholder { color: var(--ink-faint); }
.search-bar:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(244, 166, 196, 0.18); }

.puzzle-list {
  margin-top: 14px;
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 6px;
  max-height: 100%;
}

.puzzle-list::-webkit-scrollbar { width: 8px; }
.puzzle-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.puzzle-list::-webkit-scrollbar-thumb:hover { background: var(--accent-faint); }

.puzzle-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease), border-color 0.22s var(--ease);
}
.puzzle-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-soft);
}

/* Left column: name on top, tags underneath */
.puzzle-left {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
}

.puzzle-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

/* Smaller tag capsules */
.tag {
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--accent-deep);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  line-height: 1.4;
}

/* Eye on the right side */
.eye-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 999px;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
}
.eye-icon { width: 18px; height: 18px; color: var(--accent-deep); pointer-events: none; }
.eye-btn:hover { background: var(--bg-2); transform: scale(1.15); }

#list-screen .small-btn,
#difficulty-screen .small-btn {
  margin-top: 14px;
  align-self: center;
  flex: 0 0 auto;
}

/* ---------- State 3: difficulty ---------- */
.panel-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-deep);
  margin-bottom: 22px;
}

.slider-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(440px, 86%);
  margin-bottom: 10px;
}

.slider-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.diff-label {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--accent-deep);
}

.diff-info {
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-weight: 500;
}

.diff-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  outline: none;
  cursor: pointer;
  margin: 4px 0;
}
.diff-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent-2);
  box-shadow: 0 3px 10px rgba(239, 141, 180, 0.4);
  cursor: pointer;
  transition: transform 0.2s var(--ease);
}
.diff-slider::-webkit-slider-thumb:hover { transform: scale(1.18); }
.diff-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent-2);
  box-shadow: 0 3px 10px rgba(239, 141, 180, 0.4);
  cursor: pointer;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* ---------- State 4: gameplay ---------- */
#game-screen {
  padding: 0;
  background:
    radial-gradient(120% 100% at 50% 0%, #fff7fb 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
  transition: opacity 0.5s var(--ease);
}

#puzzle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.game-menu-btn {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 20;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease);
  color: var(--accent-deep);
}
.game-menu-btn:hover { transform: scale(1.08); border-color: var(--accent); }
.game-menu-btn:active { transform: scale(0.96); }

.jigsaw-icon { width: 22px; height: 22px; pointer-events: none; }

.game-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  pointer-events: none;
}
.game-loader.hidden { display: none; }
.loader-cog {
  width: 44px;
  height: 44px;
  color: var(--accent-deep);
  animation: cogSpin 1.1s linear infinite;
}
@keyframes cogSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.game-menu {
  position: absolute;
  left: 18px;
  bottom: 74px;
  z-index: 21;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 190px;
  animation: popUp 0.22s var(--ease);
}
.game-menu.hidden { display: none; }

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.menu-item:hover { background: var(--bg-2); color: var(--accent-deep); }

/* ---------- Completion overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  background: rgba(255, 240, 246, 0);
  transition: background 0.6s var(--ease);
}
.overlay.show {
  background: rgba(255, 240, 246, 0.66);
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }

.confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 31;
}

.tada-card {
  position: relative;
  z-index: 32;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 40px 30px;
  text-align: center;
  transform: scale(0.7);
  opacity: 0;
  animation: tadaPop 0.7s var(--ease) forwards;
}
@keyframes tadaPop {
  0%   { transform: scale(0.7) rotate(-6deg); opacity: 0; }
  60%  { transform: scale(1.05) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.tada-emoji { display: flex; align-items: center; justify-content: center; }
.tada-icon { width: 52px; height: 52px; color: var(--accent-deep); pointer-events: none; }
.tada-title {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent-deep);
  margin: 6px 0 2px;
  letter-spacing: 0.5px;
}
.tada-sub { color: var(--ink-soft); font-size: 0.95rem; margin-bottom: 20px; }

/* ---------- Popups ---------- */
.popup {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(120, 80, 95, 0.28);
  backdrop-filter: blur(4px);
  animation: bgFade 0.25s var(--ease);
}
.popup.hidden { display: none; }
@keyframes bgFade { from { opacity: 0; } to { opacity: 1; } }

.popup-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px 22px;
  min-width: 280px;
  max-width: 90vw;
  animation: popUp 0.3s var(--ease);
}
@keyframes popUp {
  from { transform: translateY(14px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.popup-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-deep);
  margin-bottom: 14px;
}

.tag-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 18px;
}
.tag-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.tag-list label:hover { border-color: var(--accent); background: var(--bg-2); }
.tag-list input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-2);
  cursor: pointer;
}

.popup-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.confirm-msg {
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 20px;
  line-height: 1.5;
  max-width: 360px;
}

/* ---------- Image preview popup ---------- */
#image-popup { padding: 0; }
#image-popup .close-x {
  position: absolute;
  top: 22px;
  right: 28px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-deep);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
  z-index: 2;
}
.close-icon { width: 16px; height: 16px; pointer-events: none; }
#image-popup .close-x:hover { transform: rotate(90deg) scale(1.05); background: var(--bg-2); }
.image-popup-img {
  max-width: 92vw;
  max-height: 90vh;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  object-fit: contain;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .list-controls { flex-wrap: wrap; }
  .search-bar { flex: 1 1 100%; }
  .slider-wrap { width: 92%; }
  .tags { flex-basis: 100%; margin-left: 0; justify-content: flex-start; margin-top: 4px; }
}
