:root {
  --cream: #fff8ef;
  --cream-2: #f6eadb;
  --ink: #3b2a20;
  --ink-soft: #7a6352;
  --accent: #e07a5f;
  --panel: rgba(255, 248, 239, 0.86);
  --panel-border: rgba(120, 90, 60, 0.16);
  --shadow: 0 10px 30px rgba(40, 20, 10, 0.25);
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1c130e;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.9s ease;
}
body.scene-ready #scene { opacity: 1; }

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

body.busy, body.busy * { cursor: progress !important; }

/* ------------------------------------------------------------ lobby */

#lobby {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(28, 19, 14, 0.05), rgba(28, 19, 14, 0.55));
  overflow-y: auto;
}

.lobby-card {
  width: min(560px, 100%);
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--panel-border);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 26px 26px 22px;
  animation: rise 0.6s cubic-bezier(.2, .9, .3, 1.2);
}

@keyframes rise {
  from { transform: translateY(18px) scale(0.98); opacity: 0; }
}

.lobby-card header { text-align: center; margin-bottom: 18px; }
.lobby-card h1 {
  margin: 0;
  font-size: 40px;
  letter-spacing: -0.5px;
}
.lobby-card h1 span { display: inline-block; animation: steam 3s ease-in-out infinite; }
@keyframes steam { 50% { transform: translateY(-3px) rotate(-6deg); } }
.lobby-card header p { margin: 4px 0 0; color: var(--ink-soft); }
.lobby-card header .rule { font-size: 14px; }

.you {
  display: flex;
  gap: 16px;
  align-items: center;
  background: var(--cream-2);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}

.you-preview {
  --c: #e07a5f;
  flex: none;
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  font-family: var(--emoji);
  font-size: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 65%, var(--c) 0 55%, color-mix(in srgb, var(--c) 70%, #000) 100%);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: background 0.2s;
}

.you-pickers { flex: 1; min-width: 0; display: grid; gap: 10px; }

.picker {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 2px;
}
.picker button {
  font-family: var(--emoji);
  font-size: 22px;
  aspect-ratio: 1;
  border-radius: 10px;
  transition: transform 0.12s, background 0.12s;
}
.picker button:hover { transform: scale(1.15); }
.picker button.on { background: #fff; box-shadow: 0 0 0 2px var(--accent); }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
  transition: transform 0.12s;
}
.swatches button:hover { transform: scale(1.15); }
.swatches button.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); }

.tones { display: flex; gap: 4px; }
.tones button {
  font-family: var(--emoji);
  font-size: 18px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  transition: transform 0.12s, background 0.12s;
}
.tones button:hover { transform: scale(1.12); }
.tones button.on { background: #fff; box-shadow: 0 0 0 2px var(--accent); }

.rooms { display: grid; gap: 10px; }

.room-card {
  --tint: #e07a5f;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: linear-gradient(100deg, color-mix(in srgb, var(--tint) 22%, #fff) 0%, #fffaf3 70%);
  border: 1px solid color-mix(in srgb, var(--tint) 30%, transparent);
  transition: transform 0.15s, box-shadow 0.15s;
}
.room-card:hover, .room-card:focus-visible, .room-card.selected {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--tint) 35%, transparent);
  outline: none;
}
.room-fireside { --tint: #d9622b; }
.room-greenhouse { --tint: #52b788; }
.room-rooftop { --tint: #6c63ff; }
.room-terrace { --tint: #f4a261; }

.room-emoji { font-family: var(--emoji); font-size: 32px; }
.room-text { display: grid; min-width: 0; }
.room-text b { font-size: 17px; }
.room-text small { color: var(--ink-soft); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-count {
  font-size: 13px;
  background: rgba(255, 255, 255, 0.7);
  padding: 4px 9px;
  border-radius: 99px;
  white-space: nowrap;
}
.room-go {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--tint);
  color: #fff;
  font-weight: 700;
}

/* ------------------------------------------------------------ hud */

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

.bar {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 99px;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.top-left { left: 16px; }
.top-right { right: 16px; padding-left: 14px; }
.badge { font-weight: 700; white-space: nowrap; }
.count { color: var(--ink-soft); white-space: nowrap; }
.now-playing { color: var(--ink-soft); font-style: italic; white-space: nowrap; }

.bar button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-family: var(--emoji);
  font-size: 18px;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.15s;
}
.bar button:hover { background: rgba(0, 0, 0, 0.06); transform: scale(1.08); }
.bar button.on { background: var(--accent); }

#volume { width: 80px; accent-color: var(--accent); }

.log {
  position: absolute;
  left: 16px;
  bottom: 96px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none !important;
  max-width: 260px;
}
.log .line {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  padding: 4px 12px 4px 4px;
  background: rgba(255, 248, 239, 0.8);
  border-radius: 99px;
  font-family: var(--emoji);
  font-size: 20px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
  animation: logIn 0.3s cubic-bezier(.2, .9, .3, 1.3), logOut 1s ease 14s forwards;
}
.log .line.arrival { opacity: 0.8; font-size: 16px; }
.log .who {
  --c: #ccc;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--c);
  font-size: 18px;
}
@keyframes logIn { from { transform: translateX(-20px); opacity: 0; } }
@keyframes logOut { to { opacity: 0; transform: translateY(-6px); } }

.dock {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 32px);
}

.emoji-bar {
  display: flex;
  gap: 2px;
  padding: 6px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 99px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  scrollbar-width: none;
}
.emoji-bar::-webkit-scrollbar { display: none; }
.emoji-bar button, .emoji-grid button, .menu-grid button {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-family: var(--emoji);
  font-size: 24px;
  display: grid;
  place-items: center;
  transition: transform 0.12s cubic-bezier(.2, .9, .3, 1.5), background 0.12s;
}
.emoji-bar button:hover, .emoji-grid button:hover, .menu-grid button:hover { transform: scale(1.25); background: rgba(255, 255, 255, 0.9); }
.emoji-bar button:active, .emoji-grid button:active, .menu-grid button:active { transform: scale(0.9); }
.emoji-bar .more { font-size: 18px; opacity: 0.7; }

.menu-btn, .stand {
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  font-family: var(--emoji);
  font-size: 28px;
  background: var(--accent);
  box-shadow: var(--shadow), inset 0 -4px 0 rgba(0, 0, 0, 0.15);
  transition: transform 0.15s;
}
.stand { background: var(--panel); width: 50px; height: 50px; font-size: 24px; }
.menu-btn:hover, .stand:hover { transform: scale(1.08) rotate(-4deg); }

.status {
  flex: none;
  padding: 8px 14px;
  border-radius: 99px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-family: var(--emoji);
  font-size: 20px;
  animation: bob 1s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-3px); } }

.panel {
  position: absolute;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 12px;
  animation: pop 0.2s cubic-bezier(.2, .9, .3, 1.3);
  max-width: calc(100% - 32px);
}
@keyframes pop { from { transform: translateX(-50%) translateY(10px) scale(0.96); opacity: 0; } }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(9, 42px);
  gap: 2px;
  max-height: 46vh;
  overflow-y: auto;
}
.panel-title { text-align: center; font-family: var(--emoji); font-size: 18px; margin-bottom: 6px; opacity: 0.8; }
.menu-grid { display: grid; grid-template-columns: repeat(5, 52px); gap: 6px; }
.menu-grid button { width: 52px; height: 52px; font-size: 30px; background: rgba(255, 255, 255, 0.6); }

.hint {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 99px;
  background: rgba(30, 20, 14, 0.62);
  color: #fff6e8;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none !important;
  transition: opacity 1s;
}
.hint.gone { opacity: 0; }

.toast {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  padding: 12px 22px;
  border-radius: 99px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-family: var(--emoji);
  font-size: 34px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.25s cubic-bezier(.2, .9, .3, 1.4);
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

@media (max-width: 720px) {
  .now-playing, #volume { display: none; }
  .bar { font-size: 13px; padding-left: 10px; }
  .top-left { left: 10px; }
  .top-right { right: 10px; }
  .badge { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
  .hint { top: 64px; font-size: 12px; }
  .emoji-grid { grid-template-columns: repeat(7, 42px); }
  .menu-grid { grid-template-columns: repeat(4, 52px); }
  .log { bottom: 90px; left: 10px; }
  .dock { gap: 6px; }
  .menu-btn { width: 52px; height: 52px; }
  .room-text small { white-space: normal; }
}

@media (max-width: 520px) {
  .lobby-card { padding: 20px 14px 16px; }
  .lobby-card h1 { font-size: 32px; }
  .you { flex-direction: column; gap: 10px; }
  .you-preview { width: 64px; height: 64px; font-size: 38px; }
  .swatches { justify-content: center; }
  .picker button { font-size: 20px; }
  .room-card { grid-template-columns: auto 1fr auto; padding: 10px 12px; }
  .room-go { display: none; }
}

/* ------------------------------------------------------------ suitcase */

.bag-btn {
  flex: none;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-family: var(--emoji);
  font-size: 24px;
  background: linear-gradient(160deg, #a0673f, #6e4126);
  box-shadow: var(--shadow), inset 0 -4px 0 rgba(0, 0, 0, 0.2), inset 0 0 0 2px rgba(255, 225, 170, 0.25);
  transition: transform 0.15s;
}
.bag-btn:hover { transform: scale(1.08) rotate(4deg); }

.suitcase {
  width: min(600px, calc(100% - 32px));
  padding: 0;
  overflow: hidden;
  border: 0;
  background: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.case-lid {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 12px;
  border-radius: 20px 20px 0 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 230, 190, 0.18), transparent 60%),
    linear-gradient(180deg, #9a5f37, #7a4526);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
  color: #fbe9cf;
}
.case-lid::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px dashed rgba(255, 220, 160, 0.35);
  border-bottom: 0;
  border-radius: 15px 15px 0 0;
  pointer-events: none;
}
.case-handle {
  position: absolute;
  top: -2px;
  left: 50%;
  width: 90px;
  height: 14px;
  transform: translateX(-50%);
  border: 5px solid #5c3119;
  border-top: 0;
  border-radius: 0 0 14px 14px;
  opacity: 0.85;
}
.case-title { font-family: var(--emoji); font-size: 26px; }
.case-note { font-size: 13px; opacity: 0.85; }

.case-body {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  max-height: 46vh;
  overflow-y: auto;
  padding: 18px;
  border-radius: 0 0 20px 20px;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 6px, transparent 6px 14px),
    linear-gradient(180deg, #4a1f22, #3a171a);
  box-shadow: inset 0 8px 18px rgba(0, 0, 0, 0.45);
}
.book-list { display: contents; }

.book {
  --leather: #6b2d24;
  position: relative;
  flex: none;
  width: 98px;
  height: 136px;
  padding: 18px 12px 12px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: center;
  border-radius: 3px 9px 9px 3px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.4) 0 6px, rgba(255, 255, 255, 0.1) 7px 8px, transparent 9px),
    radial-gradient(circle at 70% 15%, rgba(255, 255, 255, 0.14), transparent 55%),
    radial-gradient(circle at 50% 120%, rgba(0, 0, 0, 0.35), transparent 60%),
    var(--leather);
  box-shadow: 4px 6px 12px rgba(0, 0, 0, 0.45), inset -3px 0 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.18s cubic-bezier(.2, .9, .3, 1.4), box-shadow 0.18s;
}
.book::before {
  content: '';
  position: absolute;
  inset: 6px 6px 6px 12px;
  border: 1.5px dashed rgba(232, 206, 150, 0.45);
  border-radius: 2px 6px 6px 2px;
  pointer-events: none;
}
.book:hover { transform: translateY(-6px) rotate(-2deg); box-shadow: 6px 12px 18px rgba(0, 0, 0, 0.5); }
.book-title {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.25;
  color: #ecc874;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
  word-break: break-word;
}
.book-meta { font-size: 10.5px; color: rgba(236, 200, 116, 0.75); font-family: Georgia, serif; }
.book-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--cream);
  color: var(--ink);
  font-size: 11px;
  opacity: 0;
  transition: opacity 0.15s;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.book:hover .book-remove { opacity: 1; }

.add-books {
  flex: none;
  width: 98px;
  height: 136px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  text-align: center;
  border: 2px dashed rgba(251, 233, 207, 0.4);
  border-radius: 9px;
  color: rgba(251, 233, 207, 0.85);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.add-books:hover { background: rgba(255, 255, 255, 0.06); border-color: rgba(251, 233, 207, 0.7); }
.add-icon { font-family: var(--emoji); font-size: 30px; }
.add-books small { font-size: 11px; line-height: 1.3; }
.suitcase.busy .add-books { animation: bob 0.8s ease-in-out infinite; }
.suitcase.empty .add-books { width: 100%; height: 110px; }

/* ------------------------------------------------------------ reading */

.reader-bar {
  position: absolute;
  left: 50%;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 70px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: rgba(43, 26, 18, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 220, 160, 0.2);
  border-radius: 99px;
  box-shadow: var(--shadow);
  color: #fbe9cf;
}
.reader-bar button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-family: var(--emoji);
  font-size: 18px;
  color: #fbe9cf;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.15s;
}
.reader-bar button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); transform: scale(1.08); }
.reader-bar button:disabled { opacity: 0.3; cursor: default; }
.page-label {
  min-width: 96px;
  text-align: center;
  font-family: Georgia, serif;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
