:root {
  --ink: #3a2f3f;
  --ink-soft: #6d5d6e;
  --paper: #fbf3e4;
  --paper-2: #f3e5cc;
  --paper-3: #e8d4b0;
  --line: #b79a73;
  --line-dark: #7b5f45;
  --night: #1d1a2e;
  --night-2: #2b2642;
  --gold: #e8b64c;
  --gold-deep: #b9802a;
  --mem: #8fb7ff;
  --sand: #ffd27a;
  --rose: #ef8fa6;
  --mint: #7fcdb0;
  --sky: #8ec5ea;
  --lav: #b9a3e6;
  --r3: #9fb8c9;
  --r4: #c99cf2;
  --r5: #ffcc4d;
  --shadow: 0 3px 0 rgba(60, 40, 30, .25);
  --pix: "DotGothic16", "Zen Maru Gothic", sans-serif;
  --ui: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--ui);
  font-weight: 500;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
img { image-rendering: pixelated; }
.hidden { display: none !important; }

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(ellipse at 20% 0%, #3b3460 0%, transparent 60%),
    radial-gradient(ellipse at 100% 100%, #3a2a4a 0%, transparent 55%),
    var(--night);
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  color: #f5ecff;
  font-family: var(--pix);
  background: linear-gradient(#2c2747, #221e37);
  border-bottom: 2px solid #4a4170;
  min-height: 60px;
}
#clock { display: flex; align-items: center; gap: 10px; }
#dial { position: relative; width: 46px; height: 46px; }
#dial img { width: 100%; height: 100%; }
#dialHand {
  position: absolute; left: 50%; top: 50%; width: 3px; height: 17px; margin-left: -1.5px;
  background: #fff4cf; border-radius: 2px; transform-origin: 50% 100%;
  translate: 0 -100%; box-shadow: 0 0 4px #ffde8a;
}
#clockText { line-height: 1.05; }
#dayText { font-size: 15px; color: #ffe3a3; letter-spacing: .08em; }
#timeText { font-size: 24px; letter-spacing: .06em; }
#speed { display: flex; gap: 4px; }
#speed button {
  min-width: 38px; height: 30px; padding: 0 8px;
  background: #3b355c; border: 2px solid #5a5288; border-radius: 6px;
  color: #d8d0f5; font-family: var(--pix); font-size: 14px;
}
#speed button.on { background: #ffd981; border-color: #fff1c4; color: #4a3520; }
#speed button.locked { opacity: .35; pointer-events: none; }
#res { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.res {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 999px; padding: 3px 12px 3px 4px; min-width: 110px;
}
.res img { width: 26px; height: 26px; }
.res span { font-size: 18px; flex: 1; text-align: right; }
.res small { font-size: 11px; opacity: .7; }
.res.bump span { animation: bump .35s; }
@keyframes bump { 40% { transform: scale(1.18); color: #fff3b8; } }

/* ---------- main ---------- */
#main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 12px; padding: 12px; min-height: 0;
}
#stage {
  position: relative; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#scene {
  image-rendering: pixelated;
  border-radius: 10px;
  box-shadow: 0 0 0 3px #4a4170, 0 0 0 6px #2a2542, 0 18px 40px rgba(0, 0, 0, .5);
  background: #000;
}
#sceneUI { position: absolute; pointer-events: none; }
#sceneUI > * { pointer-events: none; }
#locLabel {
  position: absolute; left: 14px; top: 12px;
  font-family: var(--pix); color: #fff; font-size: 17px;
  padding: 4px 14px 5px; border-radius: 999px;
  background: rgba(30, 24, 48, .62); backdrop-filter: blur(3px);
  border: 1px solid rgba(255, 255, 255, .25);
}
#locLabel small { opacity: .75; margin-left: 8px; font-size: 13px; }
#bubbles, #glints, #toasts { position: absolute; inset: 0; }
.bubble {
  position: absolute; max-width: 260px;
  transform: translate(-50%, -100%);
  background: #fffaf0; color: var(--ink);
  border: 2px solid var(--line-dark); border-radius: 12px;
  padding: 7px 12px 8px; font-size: 14px; line-height: 1.5;
  box-shadow: var(--shadow);
  animation: pop .25s ease-out;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -9px; margin-left: -7px;
  border: 7px solid transparent; border-top-color: var(--line-dark); border-bottom: 0;
}
.bubble b { display: block; font-size: 11px; color: var(--ink-soft); font-weight: 700; }
.bubble.out { animation: fade .4s forwards; }
@keyframes pop { from { transform: translate(-50%, -88%) scale(.8); opacity: 0; } }
@keyframes fade { to { opacity: 0; transform: translate(-50%, -110%); } }
.glint {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  pointer-events: auto; cursor: pointer;
  background: url(../assets/ui/glint.webp) center / contain no-repeat;
  animation: glint 1.4s ease-in-out infinite, pop .3s;
  filter: drop-shadow(0 0 6px #fff6b0);
}
@keyframes glint { 50% { transform: scale(1.18) rotate(12deg); } }
.toast {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-family: var(--pix); color: #fff; white-space: nowrap;
  text-shadow: 0 2px 0 #3a2c50, 0 0 8px rgba(0, 0, 0, .5);
  animation: rise 1.6s ease-out forwards;
}
@keyframes rise { from { opacity: 0; translate: 0 10px; } 15% { opacity: 1; } to { opacity: 0; translate: 0 -40px; } }
#rewindBtn {
  position: absolute; right: 14px; top: 12px; pointer-events: auto;
  font-family: var(--pix); font-size: 14px; color: #fff;
  background: linear-gradient(#7a65c8, #5a48a6); border: 2px solid #c8b8ff;
  border-radius: 999px; padding: 5px 14px;
  box-shadow: 0 0 12px rgba(160, 130, 255, .6);
}

/* ---------- panel ---------- */
#panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--paper);
  border-radius: 12px;
  box-shadow: 0 0 0 3px var(--line-dark), 0 0 0 6px #3a2c28, 0 18px 40px rgba(0, 0, 0, .45);
  overflow: hidden;
}
#panelTabs { display: flex; background: var(--paper-3); border-bottom: 2px solid var(--line); }
#panelTabs button {
  flex: 1; padding: 10px 0 9px; border: 0; background: transparent;
  font-family: var(--pix); font-size: 16px; color: var(--ink-soft); position: relative;
}
#panelTabs button.on { background: var(--paper); color: var(--ink); }
#panelTabs button.on::after { content: ""; position: absolute; left: 25%; right: 25%; bottom: -2px; height: 3px; background: var(--gold-deep); border-radius: 3px; }
#panelTabs button .dot { position: absolute; top: 6px; right: 18%; width: 9px; height: 9px; border-radius: 50%; background: var(--rose); }
#panelBody { flex: 1; overflow: auto; padding: 12px; scrollbar-width: thin; }

.card {
  background: #fffaf1; border: 2px solid var(--paper-3); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 10px; position: relative;
  box-shadow: 0 2px 0 var(--paper-3);
}
.place { display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; align-items: center; cursor: pointer; transition: transform .12s, border-color .12s; }
.place:hover { transform: translateY(-1px); border-color: var(--line); }
.place.on { border-color: var(--gold-deep); background: linear-gradient(#fff7df, #fff1cf); box-shadow: 0 2px 0 var(--gold-deep), 0 0 0 3px rgba(232, 182, 76, .25); }
.place.echo { border-color: var(--lav); background: linear-gradient(#f7f2ff, #efe6ff); }
.place.locked { opacity: .55; cursor: default; filter: grayscale(.6); }
.place .thumb { width: 58px; height: 58px; border-radius: 10px; object-fit: cover; border: 2px solid var(--paper-3); }
.place h3 { margin: 0; font-family: var(--pix); font-weight: 400; font-size: 16px; }
.place h3 small { font-family: var(--ui); font-size: 11px; color: var(--ink-soft); margin-left: 6px; }
.place .meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.place .lv { font-family: var(--pix); font-size: 13px; text-align: right; color: var(--ink-soft); }
.place .lv b { display: block; font-size: 20px; color: var(--ink); font-weight: 400; }
.place .badge { position: absolute; top: -7px; right: -5px; background: var(--rose); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; box-shadow: 0 2px 0 #b9566d; animation: bob 1.2s ease-in-out infinite; }
.place .echoBtn { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--lav); background: #fff; color: #6a52a8; margin-top: 4px; }
@keyframes bob { 50% { translate: 0 -3px; } }
.bar { height: 7px; background: var(--paper-3); border-radius: 99px; overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #f3c25a, #f0a35a); border-radius: 99px; }
.bar.bond i { background: linear-gradient(90deg, #f6a2b7, #ef7fa0); }
.bar.tower i { background: linear-gradient(90deg, #9ab8ff, #b296ff); }

.sectionTitle { font-family: var(--pix); font-size: 14px; color: var(--ink-soft); margin: 6px 2px 8px; display: flex; align-items: center; gap: 8px; }
.sectionTitle::after { content: ""; flex: 1; height: 2px; background: var(--paper-3); }

.tool { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; }
.tool img { width: 44px; height: 44px; }
.tool h4 { margin: 0; font-size: 14px; }
.tool p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }
.btn {
  border: 2px solid var(--line-dark); background: linear-gradient(#ffe7a6, #f6c862);
  border-radius: 10px; padding: 6px 12px; font-weight: 700; font-size: 13px;
  box-shadow: 0 3px 0 var(--line-dark); white-space: nowrap; color: var(--ink);
  transition: transform .06s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line-dark); }
.btn:disabled { filter: grayscale(1); opacity: .5; cursor: default; }
.btn.purple { background: linear-gradient(#d9c8ff, #a98ef0); border-color: #5a46a0; box-shadow: 0 3px 0 #5a46a0; }
.btn.big { font-size: 16px; padding: 10px 18px; font-family: var(--pix); font-weight: 400; }
.btn small { display: block; font-size: 11px; font-weight: 500; opacity: .8; }

/* ---------- bottom nav ---------- */
#bottomnav {
  display: flex; justify-content: center; gap: 6px;
  padding: 6px 10px calc(6px + var(--safe-b));
  background: linear-gradient(#221e37, #1a1729);
  border-top: 2px solid #4a4170;
}
#bottomnav button {
  display: flex; align-items: center; gap: 6px;
  background: #2f2a4c; border: 2px solid #4f477c; border-radius: 12px;
  padding: 4px 14px 4px 6px; color: #efe8ff; font-family: var(--pix); font-size: 15px;
  position: relative; transition: transform .1s, background .1s;
}
#bottomnav button:hover { background: #3c3562; transform: translateY(-2px); }
#bottomnav img { width: 36px; height: 36px; }
#bottomnav .dot { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--rose); color: #fff; font-size: 11px; line-height: 18px; font-family: var(--ui); font-weight: 700; }

/* ---------- full screens ---------- */
#screens > .screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  background: #141026;
  color: #f3ecff;
  animation: screenIn .22s ease-out;
}
@keyframes screenIn { from { opacity: 0; transform: scale(.985); } }
.screen header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 2px solid #3e3764;
  font-family: var(--pix);
}
.screen header h2 { margin: 0; font-weight: 400; font-size: 22px; letter-spacing: .1em; }
.screen header .sub { font-size: 13px; opacity: .7; font-family: var(--ui); }
.screen header .close { margin-left: auto; background: #3b355c; border: 2px solid #5a5288; color: #fff; border-radius: 10px; font-size: 16px; padding: 4px 16px; font-family: var(--pix); }
.screen .body { flex: 1; min-height: 0; overflow: auto; position: relative; }

/* ---------- dialogue ---------- */
#dialogue { position: fixed; inset: 0; z-index: 40; }
#overlay { position: fixed; inset: 0; z-index: 50; }
#title { position: fixed; inset: 0; z-index: 60; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  #main { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 8px; padding: 8px; }
  #res { gap: 4px; }
  .res { min-width: 0; padding-right: 8px; }
  .res small { display: none; }
}
@media (max-width: 640px) {
  #topbar { flex-wrap: wrap; gap: 6px 10px; padding: 6px 10px; min-height: 0; }
  #dial { width: 36px; height: 36px; }
  #dialHand { height: 13px; }
  #timeText { font-size: 19px; }
  #dayText { font-size: 13px; }
  #speed button { min-width: 32px; height: 28px; padding: 0 5px; font-size: 12px; }
  #res { width: 100%; justify-content: space-between; margin: 0; }
  .res { flex: 1; }
  .res img { width: 20px; height: 20px; }
  .res span { font-size: 15px; }
  #bottomnav { gap: 3px; padding: 4px 4px calc(4px + var(--safe-b)); }
  #bottomnav button { flex-direction: column; gap: 0; padding: 3px 2px; flex: 1; font-size: 11px; border-radius: 10px; }
  #bottomnav img { width: 28px; height: 28px; }
  #panelBody { padding: 8px; }
  #locLabel { font-size: 13px; left: 8px; top: 8px; padding: 2px 10px 3px; }
  .bubble { font-size: 12px; max-width: 200px; padding: 5px 9px; }
}
