:root {
  --ink: #ebe5d8;
  --dim: rgba(235, 229, 216, 0.6);
  --panel: rgba(12, 14, 24, 0.9);
  --line: rgba(255, 220, 170, 0.25);
  --warm: #f2a03d;
  --cantor: #8fd4ff;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #05060c; color: var(--ink); font-family: var(--mono); }
canvas { display: block; position: fixed; inset: 0; }
.hidden { display: none !important; }
button {
  font: 600 14px var(--mono); color: var(--ink); background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line); padding: 10px 18px; border-radius: 3px; cursor: pointer; letter-spacing: 0.04em;
}
button:hover { background: rgba(242, 160, 61, 0.18); border-color: var(--warm); }
button.ghost { background: none; color: var(--dim); }
kbd {
  display: inline-block; font: 600 11px var(--mono); padding: 1px 6px; margin: 0 2px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; color: var(--warm);
}

/* toasts */
#toasts { position: fixed; top: 46px; left: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 20; pointer-events: none; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--panel); border-left: 3px solid var(--dim); padding: 8px 12px; font-size: 12px; line-height: 1.45;
  animation: tin 0.4s ease-out; transition: opacity 0.8s, transform 0.8s;
}
.toast b { display: block; font-size: 10px; letter-spacing: 0.14em; color: var(--dim); }
.toast span { display: block; }
.toast.log { border-color: var(--warm); }
.toast.log b { color: var(--warm); }
.toast.rumor { border-color: var(--cantor); }
.toast.rumor b { color: var(--cantor); }
.toast.warn { border-color: #ff7a6a; }
.toast.warn b { color: #ff9a8a; }
.toast.out { opacity: 0; transform: translateX(-12px); }
@keyframes tin { from { opacity: 0; transform: translateX(-12px); } }

#prompt {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 15;
  background: var(--panel); padding: 7px 14px; font-size: 13px; border: 1px solid var(--line); border-radius: 3px; pointer-events: none; white-space: nowrap;
}

/* dialogue + writing */
#panel {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30;
  width: min(720px, calc(100vw - 32px)); max-height: 62vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 16px 20px 12px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
}
#p-title { font: 600 22px var(--serif); color: var(--warm); margin-bottom: 8px; }
#p-lines { overflow-y: auto; font: 18px/1.5 var(--serif); }
#p-lines .line { margin: 0 0 10px; }
#p-lines .line:not(:last-child) { opacity: 0.55; }
#p-lines .spk { font: 600 11px var(--mono); letter-spacing: 0.12em; color: var(--warm); margin-right: 8px; }
#p-lines .note { font: italic 14px var(--serif); color: var(--dim); margin-bottom: 10px; }
#panel.cantor { border-color: rgba(143, 212, 255, 0.35); }
#panel.cantor #p-title { color: var(--cantor); }
#panel.cantor .spk { color: var(--cantor); }
#panel.cantor #p-lines { text-shadow: 0 0 14px rgba(143, 212, 255, 0.25); }
#p-opts { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
#p-opts button { text-align: left; font: 15px var(--serif); padding: 8px 12px; }
#p-opts button kbd { margin-right: 8px; }
#p-hint { font-size: 11px; color: var(--dim); margin-top: 8px; text-align: right; }
#panel.text, #panel.cantor { cursor: pointer; }

/* ship log */
#log {
  position: fixed; inset: 5vh 5vw; z-index: 40; background: rgba(10, 12, 20, 0.96); border: 1px solid var(--line);
  border-radius: 4px; display: flex; flex-direction: column; box-shadow: 0 10px 80px rgba(0, 0, 0, 0.8);
}
.log-head { display: flex; align-items: baseline; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--line); gap: 12px; flex-wrap: wrap; }
.log-head h2 { margin: 0; font: 600 28px var(--serif); color: var(--warm); }
#log-stats { color: var(--dim); font-size: 12px; }
.log-body { flex: 1; display: flex; min-height: 0; }
#log-nav { width: 230px; border-right: 1px solid var(--line); overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
#log-nav button { display: flex; justify-content: space-between; align-items: center; text-align: left; font-size: 12px; border-color: transparent; background: none; padding: 9px 10px; }
#log-nav button small { color: var(--dim); }
#log-nav button.on { background: rgba(242, 160, 61, 0.14); border-color: var(--line); }
#log-nav button.fresh span::after { content: " •"; color: var(--warm); }
#log-entries { flex: 1; overflow-y: auto; padding: 18px 26px; }
.entry { max-width: 640px; margin-bottom: 18px; padding-left: 14px; border-left: 2px solid var(--line); }
.entry h4 { margin: 0 0 4px; font: 600 20px var(--serif); }
.entry h4 em { font: 600 10px var(--mono); color: var(--warm); letter-spacing: 0.1em; vertical-align: middle; text-transform: uppercase; }
.entry p { margin: 0; font: 17px/1.5 var(--serif); color: rgba(235, 229, 216, 0.88); white-space: pre-wrap; }
.entry.new { border-color: var(--warm); }
.entry.rumor { border-color: rgba(143, 212, 255, 0.4); border-left-style: dashed; }
.entry.rumor h4 { color: var(--cantor); }
.entry.rumor p { font-style: italic; color: var(--dim); }
.empty { color: var(--dim); font: italic 18px var(--serif); }
.log-foot { padding: 10px 22px; border-top: 1px solid var(--line); font-size: 11px; color: var(--dim); }

/* glyph door */
#glyph {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 40; text-align: center;
  background: rgba(14, 8, 24, 0.96); border: 1px solid rgba(200, 160, 255, 0.4); border-radius: 4px; padding: 22px 26px;
  width: min(560px, calc(100vw - 32px)); box-shadow: 0 0 80px rgba(160, 100, 255, 0.25);
}
#glyph h3 { margin: 0 0 4px; font: 600 26px var(--serif); color: #d8b8ff; }
#glyph p { font: italic 16px var(--serif); color: var(--dim); margin: 0 0 14px; }
#g-slots { display: flex; justify-content: center; gap: 8px; margin: 10px 0; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px; border: 1px solid transparent; border-radius: 4px; }
.slot.sel { border-color: rgba(220, 180, 255, 0.7); background: rgba(200, 160, 255, 0.08); }
.slot button { padding: 2px 10px; font-size: 11px; }
.slot .gl { font: 34px/1.3 serif; width: 52px; color: #f0dcff; text-shadow: 0 0 12px rgba(220, 170, 255, 0.7); cursor: pointer; }
.g-msg { font-style: normal !important; font-family: var(--mono) !important; font-size: 11px !important; }
.g-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#glyph.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translate(calc(-50% - 8px), -50%); } 40%, 80% { transform: translate(calc(-50% + 8px), -50%); } }

/* menu */
#menu {
  position: fixed; inset: 0; z-index: 50; background: rgba(4, 5, 10, 0.86); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 16px; overflow-y: auto;
}
#menu h2 { font: 600 34px var(--serif); margin: 0 0 8px; color: var(--warm); }
#menu > button { width: min(320px, 100%); }
.controls { max-width: 560px; margin-top: 18px; font-size: 12px; color: var(--dim); line-height: 1.9; }
.controls h4 { margin: 10px 0 0; color: var(--ink); font-weight: 600; letter-spacing: 0.1em; font-size: 11px; }
.controls p { margin: 0; }

/* title */
#title {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 110%, rgba(255, 120, 60, 0.12), transparent 60%);
}
.t-inner { max-width: 640px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.t-pre { font: italic 18px var(--serif); color: var(--dim); margin: 0; letter-spacing: 0.04em; }
#title h1 { font: 400 clamp(46px, 10vw, 96px)/1 var(--serif); margin: 0; letter-spacing: 0.02em; color: #fff3e4; text-shadow: 0 0 40px rgba(255, 150, 80, 0.35); }
.t-sub { font: 20px/1.5 var(--serif); color: rgba(235, 229, 216, 0.8); margin: 4px 0 18px; }
#btn-begin { font-size: 16px; padding: 12px 34px; }
#title-stats { font-size: 12px; color: var(--dim); min-height: 1em; margin: 6px 0 0; }
.t-foot { font-size: 11px; color: rgba(235, 229, 216, 0.4); margin-top: 18px; }

/* ending */
#ending { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; cursor: pointer; }
#end-text { font: 26px/1.5 var(--serif); max-width: 760px; opacity: 0; color: #fff6ea; text-shadow: 0 0 20px rgba(0, 0, 0, 0.9); }
#end-text.show { animation: endin 2.2s ease forwards; }
#end-text.big { font-size: clamp(40px, 8vw, 80px); letter-spacing: 0.08em; }
@keyframes endin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
#end-hint { position: fixed; bottom: 18px; right: 22px; font-size: 11px; color: rgba(255, 255, 255, 0.3); }
#end-credits { max-width: 720px; cursor: default; animation: endin 3s ease forwards; background: rgba(0, 0, 0, 0.55); padding: 24px; border-radius: 4px; }
#end-credits h1 { font: 400 54px var(--serif); margin: 0 0 6px; }
#end-stats { color: var(--warm); font-size: 13px; }
.cred { font: 17px/1.6 var(--serif); color: rgba(235, 229, 216, 0.8); }

@media (max-width: 640px) {
  #log { inset: 8px; }
  .log-body { flex-direction: column; }
  #log-nav { width: auto; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); }
  #log-nav button { white-space: nowrap; }
  #p-lines { font-size: 16px; }
}
