:root{
  --bg:#0a0a0a;
  --surface:#17181c;
  --surface-2:#1f2025;
  --hairline:#2a2b30;
  --text:#f5f5f0;
  --text-dim:#9a9a9f;
  --gold:#ffcc00;
  --pink:#ff3b7f;
  --blue:#2e7dff;
  --green:#2ecc71;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*{box-sizing:border-box;}
html,body{
  margin:0; padding:0; height:100%;
  background:var(--bg); color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  -webkit-tap-highlight-color:transparent;
  overscroll-behavior:none;
}

#app{
  height:100%;
  display:flex;
  flex-direction:column;
}

.screen{
  display:none;
  flex-direction:column;
  height:100%;
  overflow:hidden;
}
.screen.active{ display:flex; }

/* ---------- Header ---------- */
.topbar{
  padding: calc(18px + var(--safe-top)) 20px 14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  border-bottom:1px solid var(--hairline);
  flex-shrink:0;
}
.wordmark{
  font-weight:900;
  font-size:22px;
  letter-spacing:-0.02em;
  text-transform:uppercase;
  color:var(--gold);
  -webkit-text-stroke: 0.5px rgba(0,0,0,.15);
}
.wordmark small{
  display:block;
  font-weight:500;
  font-size:11px;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:var(--text-dim);
  -webkit-text-stroke:0;
  margin-top:2px;
}
.back-btn{
  appearance:none; border:none; background:var(--surface);
  color:var(--text); border-radius:12px;
  width:40px; height:40px;
  display:flex; align-items:center; justify-content:center;
  font-size:20px;
}
.back-btn:active{ background:var(--surface-2); }

.subheader{
  padding:16px 20px 6px;
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  flex-shrink:0;
}
.subheader h1{
  font-size:19px;
  margin:0;
  font-weight:800;
  letter-spacing:-0.01em;
}
.subheader .count{
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:13px;
  color:var(--text-dim);
}

/* ---------- Home list ---------- */
.scroll{
  flex:1;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  padding: 14px 16px calc(24px + var(--safe-bottom));
}

.type-card{
  display:flex;
  align-items:center;
  gap:14px;
  background:var(--surface);
  border:1px solid var(--hairline);
  border-radius:16px;
  padding:16px 16px;
  margin-bottom:12px;
}
.type-card:active{ background:var(--surface-2); }
.type-dot{
  width:14px; height:14px; border-radius:50%;
  flex-shrink:0;
}
.type-dot.sliding{ background:var(--blue); }
.type-dot.twod{ background:var(--gold); }
.type-dot.pyramid{ background:var(--pink); }

.type-info{ flex:1; min-width:0; }
.type-info .name{
  font-weight:800;
  font-size:16px;
  text-transform:uppercase;
  letter-spacing:-0.01em;
}
.type-info .desc{
  font-size:13px;
  color:var(--text-dim);
  margin-top:2px;
}
.type-progress{
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:13px;
  color:var(--text-dim);
  flex-shrink:0;
}
.chev{ color:var(--text-dim); font-size:18px; flex-shrink:0; }

.legend-link{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px;
  border:1px dashed var(--hairline);
  border-radius:16px;
  color:var(--text-dim);
  font-size:13px;
  margin-top:8px;
}

.reset-link{
  appearance:none;
  display:block;
  width:100%;
  background:none;
  border:none;
  color:#b23b3b;
  font-size:13px;
  text-align:center;
  padding:18px 10px 6px;
  font-family:inherit;
}
.reset-link:active{ opacity:.6; }

.overall-progress{
  margin: 4px 4px 18px;
  padding:14px 16px;
  background:linear-gradient(135deg, #1a1a1a, #101010);
  border:1px solid var(--hairline);
  border-radius:16px;
}
.overall-progress .label{
  font-size:12px; color:var(--text-dim); text-transform:uppercase; letter-spacing:.08em; margin-bottom:8px;
}
.bar-track{
  height:8px; background:var(--surface-2); border-radius:6px; overflow:hidden;
}
.bar-fill{
  height:100%;
  background:linear-gradient(90deg, var(--blue), var(--gold), var(--pink));
  width:0%;
  transition:width .3s ease;
}
.overall-progress .num{
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:13px;
  color:var(--text);
}
.progress-row{
  margin-top:8px;
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.progress-row .num{ margin-top:0; }
.reset-btn{
  appearance:none;
  background:none;
  border:1px solid var(--hairline);
  color:var(--pink);
  font-size:12px;
  font-weight:600;
  padding:7px 12px;
  border-radius:10px;
  flex-shrink:0;
}
.reset-btn:active{ background:var(--surface-2); }

/* ---------- Puzzle grid ---------- */
.grid{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
}
.grid.wide{ grid-template-columns:repeat(3,1fr); }

.tile{
  aspect-ratio:1;
  background:var(--surface);
  border:1px solid var(--hairline);
  border-radius:12px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  position:relative;
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-weight:600;
  font-size:15px;
}
.grid.wide .tile{ font-size:12px; padding:4px; text-align:center; }
.tile:active{ background:var(--surface-2); }
.tile.solved{ border-color:var(--green); }
.tile .star{
  position:absolute; top:5px; right:6px;
  font-size:10px; color:var(--green);
  opacity:0;
}
.tile.solved .star{ opacity:1; }
.tile .tile-time{
  font-size:9px;
  color:var(--text-dim);
  margin-top:3px;
  font-weight:500;
}

/* ---------- Viewer ---------- */
#screen-viewer{ background:#000; }
.viewer-topbar{
  padding: calc(14px + var(--safe-top)) 14px 10px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  flex-shrink:0;
  background:rgba(10,10,10,.9);
  z-index:2;
}

.viewer-timer{
  text-align:center;
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:28px;
  font-weight:700;
  letter-spacing:.02em;
  color:var(--gold);
  padding:2px 0 10px;
  flex-shrink:0;
  background:rgba(10,10,10,.9);
}
.viewer-timer.solved{ color:var(--green); }
.viewer-timer .label{
  display:block;
  font-size:10px;
  font-weight:500;
  letter-spacing:.1em;
  text-transform:uppercase;
  color:var(--text-dim);
  margin-top:2px;
}
.viewer-title-block{
  display:flex;
  flex-direction:column;
  align-items:center;
  min-width:0;
}
.viewer-title{
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:14px;
  color:var(--text-dim);
}
.viewer-timer{
  appearance:none;
  border:none;
  background:none;
  padding:0;
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:17px;
  font-weight:700;
  color:var(--gold);
  margin-top:3px;
  letter-spacing:.02em;
  cursor:pointer;
}
.viewer-timer.is-recorded{ color:var(--green); }

.big-timer-overlay{
  position:fixed;
  inset:0;
  background:rgba(6,6,6,.95);
  display:none;
  align-items:center;
  justify-content:center;
  flex-direction:column;
  z-index:50;
}
.big-timer-overlay.show{ display:flex; }
.big-timer-value{
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-weight:800;
  font-size:min(20vw, 96px);
  color:var(--gold);
  letter-spacing:.02em;
}
.big-timer-value.is-recorded{ color:var(--green); }
.big-timer-hint{
  margin-top:16px;
  font-size:13px;
  color:var(--text-dim);
}

.timer-bar{
  display:flex;
  gap:8px;
  padding:10px 14px;
  background:rgba(10,10,10,.9);
  flex-shrink:0;
  z-index:2;
}
.timer-btn{
  appearance:none;
  border:1px solid var(--hairline);
  background:var(--surface);
  color:var(--text);
  border-radius:10px;
  padding:9px 6px;
  font-size:12px;
  font-weight:700;
  flex:1;
  white-space:nowrap;
}
.timer-btn:active{ background:var(--surface-2); }
.timer-btn:disabled{ opacity:.32; }
#timer-start{ color:var(--green); border-color:var(--green); }
#timer-pause{ color:var(--gold); border-color:var(--gold); }
#timer-stop{ color:var(--pink); border-color:var(--pink); }
.timer-bar.hidden{ display:none; }
.icon-btn{
  appearance:none; border:none; background:var(--surface);
  color:var(--text); border-radius:12px;
  width:40px; height:40px;
  display:flex; align-items:center; justify-content:center;
  font-size:18px;
}
.icon-btn.solved-btn.on{ color:var(--green); }

.viewer-stage{
  flex:1;
  position:relative;
  overflow:hidden;
  touch-action:none;
  display:flex;
  align-items:center;
  justify-content:center;
}
.viewer-stage img{
  max-width:100%;
  max-height:100%;
  will-change:transform;
  user-select:none;
  -webkit-user-drag:none;
  transform-origin:0 0;
}

.viewer-bottombar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 18px calc(16px + var(--safe-bottom));
  flex-shrink:0;
  background:rgba(10,10,10,.9);
}
.nav-btn{
  appearance:none; border:none; background:var(--surface);
  color:var(--text); border-radius:14px;
  padding:12px 20px;
  font-size:15px;
  font-weight:700;
  flex:1;
}
.nav-btn:first-child{ margin-right:8px; }
.nav-btn:last-child{ margin-left:8px; }
.nav-btn:disabled{ opacity:.3; }
.viewer-count{
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:12px;
  color:var(--text-dim);
  white-space:nowrap;
}

.hint{
  text-align:center;
  font-size:11px;
  color:var(--text-dim);
  padding-bottom:6px;
}

/* ---------- Legend screen ---------- */
.legend-img-wrap{
  padding:16px;
  overflow:auto;
}
.legend-img-wrap img{ width:100%; border-radius:12px; }
.legend-text{
  padding:0 20px 20px;
  color:var(--text-dim);
  font-size:14px;
  line-height:1.5;
}

::-webkit-scrollbar{ display:none; }
