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

:root {
  --bg-main:  #0A1A2A;
  --bg2:      #122A40;
  --bg3:      #1A3A58;
  --accent:   #60C0E0;
  --accent2:  #90D8F0;
  --accent3:  #40A0C0;
  --parch:    #E8F4FA;
  --muted:    rgba(232,244,250,0.50);
  --cream:    #F0F8FC;
  --cream2:   #DCE8F0;
  --ink:      #0A1A2A;
  --ink2:     #2A3A50;
  --ink3:     #5A6A80;
  --red:      #D04050;
  --amber:    #E0A030;
  --ok:       #40A0B0;
  --r:        12px;
  --r-sm:     8px;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Source Sans 3', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.screen.hidden { opacity: 0; pointer-events: none; transform: scale(0.97); }

#entry {
  background: var(--bg-main);
  overflow: hidden;
  padding: 0 1rem;
}

.bg-particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floater {
  position: absolute; opacity: 0; user-select: none;
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  0%   { opacity:0;    transform: translateY(0)      rotate(0deg)  scale(0.7); }
  8%   { opacity:0.15; }
  85%  { opacity:0.09; }
  100% { opacity:0;    transform: translateY(-110vh) rotate(22deg) scale(1.1); }
}

.entry-box {
  position: relative; z-index: 2;
  display: flex; flex-direction: column;
  align-items: center; text-align: center;
  gap: clamp(8px, 1.6vh, 18px);
  width: 100%; max-width: 460px;
}

.entry-badge {
  font-size: 10px; font-weight: 600; letter-spacing: 2px;
  text-transform: uppercase; color: var(--accent);
  background: rgba(255,255,255,0.06);
  border: 0.5px solid rgba(255,255,255,0.15);
  border-radius: 20px; padding: 5px 14px;
}

.entry-icons {
  display: flex; gap: 10px;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  animation: popIn 0.7s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes popIn {
  from { opacity:0; transform: scale(0.5); }
  to   { opacity:1; transform: scale(1); }
}

.entry-h1 {
  font-family: 'Josefin Sans', Georgia, serif;
  font-size: clamp(1.7rem, 5.5vw, 3rem);
  font-weight: 900; color: var(--parch);
  line-height: 1.1; letter-spacing: -0.3px;
}
.entry-h1 em { font-style: normal; color: var(--accent); }

.entry-sub {
  font-size: clamp(12px, 2.2vw, 15px);
  color: var(--muted); line-height: 1.55;
  max-width: 320px;
}

.entry-stages { display: flex; gap: 8px; width: 100%; justify-content: center; }
.stage-chip {
  flex: 1; max-width: 130px;
  background: rgba(255,255,255,0.055);
  border: 0.5px solid rgba(255,255,255,0.10);
  border-radius: var(--r);
  padding: clamp(8px,1.5vh,14px) 8px;
  display: flex; flex-direction: column;
  align-items: center; gap: 3px;
}
.sc-icon { font-size: clamp(1.2rem,3vw,1.6rem); }
.sc-name { font-size: clamp(10px,1.8vw,12px); font-weight: 600; color: var(--accent2); }
.sc-size { font-size: clamp(9px,1.5vw,11px); color: var(--muted); }

.btn-play {
  display: inline-flex; align-items: center; gap: 10px;
  padding: clamp(11px,1.8vh,15px) clamp(28px,5vw,44px);
  font-family: 'Source Sans 3', sans-serif;
  font-size: clamp(14px,2.5vw,17px); font-weight: 600;
  color: var(--bg-main); background: var(--accent);
  border: none; border-radius: 50px; cursor: pointer;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
}
.btn-play:hover { background: var(--accent2); transform: translateY(-2px) scale(1.03); }
.btn-play:active { transform: scale(0.97); }
.btn-play .arr { font-size: 1.1em; transition: transform 0.15s; }
.btn-play:hover .arr { transform: translateX(4px); }

.entry-tip {
  font-size: clamp(10px,1.8vw,12px); color: var(--muted);
}

.entry-footer {
  position: absolute; bottom: clamp(10px,2vh,20px); left: 0; right: 0;
  display: flex; justify-content: center; gap: 18px;
  font-size: 11px; z-index: 3;
}
.entry-footer a {
  color: var(--muted); text-decoration: none; opacity: 0.7;
  transition: opacity 0.2s;
}
.entry-footer a:hover { opacity: 1; text-decoration: underline; }

#game {
  background: var(--cream);
  padding: 0;
  justify-content: flex-start;
  overflow: hidden;
}

.game-wrap {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center;
  padding: clamp(6px,1.5vh,14px) clamp(8px,2vw,20px) clamp(6px,1vh,12px);
  gap: clamp(4px,0.8vh,10px);
  max-width: 580px;
  margin: 0 auto;
}

.topbar {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.g-title {
  font-family: 'Josefin Sans', Georgia, serif;
  font-size: clamp(16px,3vw,20px); font-weight: 700; color: var(--ink);
}
.g-title span { color: var(--ok); }
.topbar-pills { display: flex; gap: 6px; }
.pill {
  display: flex; align-items: center; gap: 4px;
  background: var(--cream2); border: 0.5px solid rgba(0,0,0,0.10);
  border-radius: 20px; padding: 4px 11px;
  font-size: clamp(11px,2vw,13px); font-weight: 600; color: var(--ink2);
  white-space: nowrap;
}

.phase-tabs { display: flex; gap: 5px; width: 100%; flex-shrink: 0; }
.ptab {
  flex: 1; padding: 5px 4px;
  border-radius: var(--r-sm);
  border: 0.5px solid rgba(0,0,0,0.10);
  background: white;
  font-size: clamp(10px,1.8vw,12px); font-weight: 600;
  color: var(--ink3); text-align: center; line-height: 1.3;
  transition: all 0.15s;
}
.ptab .pt-ic { font-size: clamp(12px,2vw,15px); display: block; }
.ptab .pt-sz { font-size: 9px; font-weight: 400; display: block; color: var(--ink3); }
.ptab.active { background: var(--bg2); color: var(--accent2); border-color: var(--bg-main); }
.ptab.active .pt-sz { color: rgba(255,255,255,0.4); }
.ptab.done { background: #EAF3DE; color: #3B6D11; border-color: #aad48a; }

.timer-wrap { width: 100%; flex-shrink: 0; }
.timer-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 4px;
}
.timer-lbl {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--ink3);
}
.timer-val {
  font-family: 'Josefin Sans', Georgia, serif;
  font-size: clamp(18px,3.5vw,24px); font-weight: 700; color: var(--ink);
  transition: color 0.4s; min-width: 48px; text-align: right;
}
.timer-val.amber { color: var(--amber); }
.timer-val.red   { color: var(--red); animation: blink 0.7s ease infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.5} }
.tbar-bg { height: 6px; background: rgba(0,0,0,0.07); border-radius: 3px; overflow: hidden; }
.tbar-fill {
  height: 100%; border-radius: 3px;
  transition: width 1s linear, background 0.5s;
  background: var(--ok);
}
.tbar-fill.amber { background: var(--amber); }
.tbar-fill.red   { background: var(--red); }

.board-zone {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  width: 100%;
}

#board {
  display: grid;
  background: var(--cream2);
  border: 0.5px solid rgba(0,0,0,0.12);
  border-radius: var(--r);
  box-shadow: 0 4px 20px rgba(0,0,0,0.10);
  touch-action: none; user-select: none; -webkit-user-select: none;
}

.tile {
  border-radius: 9px; cursor: pointer; position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  transition: transform 0.11s ease;
  will-change: transform; border: none;
  -webkit-user-select: none; user-select: none;
}
.tile:active { transform: scale(0.91) !important; }
.tile.movable:hover { transform: scale(1.06); box-shadow: 0 5px 16px rgba(0,0,0,0.20); }
.tile.empty {
  background: var(--cream2) !important;
  cursor: default; border: 1.5px dashed rgba(0,0,0,0.12) !important;
  box-shadow: none !important;
}
.tile.empty:hover { transform: none !important; }
.tile.correct::after {
  content: ''; position: absolute; inset: 0;
  border: 2.5px solid rgba(255,255,255,0.62);
  border-radius: inherit; pointer-events: none;
}
.tile-icon { line-height: 1; pointer-events: none; }
.tile-name {
  font-size: 9px; font-weight: 600;
  color: rgba(255,255,255,0.88); pointer-events: none;
  letter-spacing: 0.1px; text-align: center; padding: 0 3px;
}
.tile-num {
  position: absolute; top: 3px; right: 4px;
  font-size: 8px; font-weight: 700;
  color: rgba(255,255,255,0.48); pointer-events: none; line-height: 1;
}

.tc0{background:#4090B0} .tc1{background:#508090} .tc2{background:#3AAOC0} .tc3{background:#608090} .tc4{background:#40A0B0} .tc5{background:#5090A0} .tc6{background:#3080C0} .tc7{background:#6090A0} .tc8{background:#4080B0} .tc9{background:#5090C0} .tc10{background:#3AAOA0} .tc11{background:#6080B0} .tc12{background:#40A0A0} .tc13{background:#5080C0} .tc14{background:#3090B0} .tc15{background:#60A0A0} 

.prog-wrap { width: 100%; flex-shrink: 0; }
.prog-row {
  display: flex; justify-content: space-between;
  font-size: clamp(10px,1.8vw,12px); font-weight: 500; color: var(--ink3);
  margin-bottom: 4px;
}
.prog-row strong { color: var(--ink2); }
.prog-bg { height: 5px; background: rgba(0,0,0,0.07); border-radius: 3px; overflow: hidden; }
.prog-fill {
  height: 100%; background: var(--ok); border-radius: 3px;
  transition: width 0.4s cubic-bezier(.4,0,.2,1); width: 0%;
}

.game-controls {
  display: flex; gap: 8px; flex-shrink: 0; width: 100%; justify-content: center;
}
.ctrl-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: clamp(7px,1.2vh,10px) clamp(12px,2.5vw,20px);
  border-radius: var(--r-sm);
  border: 0.5px solid rgba(0,0,0,0.12);
  background: white; color: var(--ink2);
  font-family: 'Source Sans 3', sans-serif;
  font-size: clamp(11px,2vw,13px); font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07);
}
.ctrl-btn:hover { background: var(--cream2); }
.ctrl-btn:active { transform: scale(0.96); }
.ctrl-btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.modal-back {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.70); z-index: 100;
  align-items: center; justify-content: center;
  padding: 1.5rem;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-back.show { display: flex; }

.modal-card {
  background: white; border-radius: 20px;
  padding: clamp(1.4rem,3vh,2.2rem) clamp(1.2rem,3vw,2rem);
  max-width: 340px; width: 100%; text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35);
  animation: mIn 0.3s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes mIn {
  from { opacity:0; transform: scale(0.78) translateY(28px); }
  to   { opacity:1; transform: scale(1)    translateY(0);    }
}

.m-emoji { font-size: clamp(44px,8vh,60px); display: block; margin-bottom: 0.4rem; }
.m-title {
  font-family: 'Josefin Sans', Georgia, serif;
  font-size: clamp(20px,4vh,26px); font-weight: 900; margin-bottom: 0.3rem;
}
.m-title.win { color: var(--ok); }
.m-title.lose { color: var(--red); }
.m-sub { font-size: clamp(12px,2vh,14px); color: var(--ink3); line-height: 1.55; margin-bottom: 0.7rem; }
.m-div { width: 36px; height: 1px; background: rgba(0,0,0,0.10); margin: 0 auto 0.9rem; }

.m-stats { display: flex; justify-content: center; gap: 20px; margin-bottom: 1.1rem; }
.mstat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.mstat-v {
  font-family: 'Josefin Sans', Georgia, serif;
  font-size: clamp(18px,3.5vh,22px); font-weight: 700; color: var(--ink);
}
.mstat-l { font-size: 10px; font-weight: 600; color: var(--ink3); text-transform: uppercase; letter-spacing: 0.8px; }

.m-actions { display: flex; flex-direction: column; gap: 8px; }
.mbtn {
  width: 100%; padding: clamp(10px,2vh,13px);
  border-radius: 10px; border: none;
  font-family: 'Source Sans 3', sans-serif;
  font-size: clamp(13px,2.5vh,15px); font-weight: 600;
  cursor: pointer; transition: transform 0.12s, background 0.12s;
}
.mbtn:active { transform: scale(0.97); }
.mbtn-p { background: var(--bg-main); color: var(--accent2); }
.mbtn-p:hover { background: var(--bg2); }
.mbtn-s { background: var(--cream2); color: var(--ink2); border: 0.5px solid rgba(0,0,0,0.10); }
.mbtn-s:hover { background: #ddd; }

@keyframes tileIn {
  from { opacity:0; transform: scale(0.80); }
  to   { opacity:1; transform: scale(1); }
}
.tile-in { animation: tileIn 0.17s cubic-bezier(.34,1.4,.64,1) both; }
@keyframes tileBump {
  0%,100%{transform:scale(1)} 40%{transform:scale(0.84)} 70%{transform:scale(1.06)}
}
.tile-bump { animation: tileBump 0.22s ease; }
