:root {
  color-scheme: dark;
  --bg: #090d14;
  --surface: #111827;
  --surface-raised: #182234;
  --surface-soft: #202c40;
  --text: #f8fafc;
  --muted: #aebcd0;
  --faint: #8190a6;
  --border: #344157;
  --primary: #3b82f6;
  --primary-strong: #2563eb;
  --accent: #f97316;
  --danger: #f87171;
  --success: #34d399;
  --focus: #93c5fd;
  --radius: 14px;
  --font-heading: "Outfit", "Avenir Next", system-ui, sans-serif;
  --font-body: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-height: 100dvh;
  --app-top: 0px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-width: 0; max-width: 100%; overflow: hidden; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font-body); }
button, input, textarea, select { font: inherit; }
button, input, textarea, select, a { touch-action: manipulation; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .45; }
.hidden { display: none !important; }

.app-shell { position: fixed; top: var(--app-top); left: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); width: 100%; max-width: 100vw; height: var(--app-height); min-width: 0; overflow: hidden; }
.sidebar { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); background: #0d131e; padding: calc(20px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; min-height: 48px; margin-bottom: 24px; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 9px; object-fit: cover; }
.brand strong, .brand span { display: block; }
.brand strong { font: 600 18px/1.2 var(--font-heading); letter-spacing: .01em; }
.brand span { margin-top: 3px; color: var(--muted); font-size: 12px; }

.button { min-height: 48px; border: 1px solid transparent; border-radius: 10px; padding: 11px 18px; color: white; font-weight: 650; transition: background-color .2s, border-color .2s, opacity .2s; }
.button:active, .icon-button:active, .send-button:active, .suggestion:active { opacity: .72; }
.button-primary { background: var(--primary-strong); box-shadow: 0 6px 20px rgba(37, 99, 235, .2); }
.button-primary:hover { background: #1d4ed8; }
.button-secondary { border-color: var(--border); background: transparent; color: var(--muted); }
.button-secondary:hover { background: var(--surface-raised); color: var(--text); }
.button-full { width: 100%; }
.button svg, .icon-button svg, .send-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button svg { vertical-align: middle; margin-right: 8px; }

.campaign-list { display: flex; flex: 1; min-height: 0; flex-direction: column; gap: 6px; overflow-y: auto; margin: 18px -6px 0; padding: 0 6px; }
.world-manager-button { margin-top: 9px; }
.campaign-item { width: 100%; min-height: 64px; border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; text-align: left; background: transparent; color: var(--text); transition: background-color .2s, border-color .2s; }
.campaign-item:hover { background: var(--surface); }
.campaign-item.active { background: var(--surface-raised); border-color: var(--border); }
.campaign-item strong, .campaign-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campaign-item strong { font-size: 14px; }
.campaign-item span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.sidebar-footer { display: flex; align-items: center; gap: 8px; min-height: 44px; color: var(--muted); font-size: 12px; }
.connection-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--faint); }
.connection-dot.online { background: var(--success); box-shadow: 0 0 0 3px rgba(52, 211, 153, .12); }

.sidebar-scrim { display: none; position: fixed; inset: 0; z-index: 15; border: 0; background: rgba(0, 0, 0, .6); }
.main { position: relative; width: 100%; max-width: 100%; min-width: 0; height: 100%; overflow: hidden; background: radial-gradient(circle at 60% -20%, rgba(37, 99, 235, .13), transparent 35%), var(--bg); }
.topbar { position: absolute; inset: 0 0 auto; z-index: 10; display: flex; align-items: center; gap: 12px; height: calc(72px + var(--safe-top)); padding: var(--safe-top) 24px 0; border-bottom: 1px solid rgba(52, 65, 87, .75); background: rgba(9, 13, 20, .88); backdrop-filter: blur(14px); }
.campaign-heading { flex: 1; min-width: 0; }
.campaign-heading h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 18px/1.25 var(--font-heading); }
.campaign-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.icon-button { display: inline-grid; place-items: center; width: 48px; height: 48px; flex: 0 0 auto; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--muted); transition: color .2s, background-color .2s, border-color .2s; }
.icon-button:hover:not(:disabled) { color: var(--text); background: var(--surface-raised); border-color: var(--border); }
.danger-button:hover:not(:disabled), .turn-delete:hover:not(:disabled) { color: #fecaca; background: rgba(127, 29, 29, .28); border-color: rgba(248, 113, 113, .45); }
.mobile-only { display: none; }

.empty-state { display: flex; height: 100%; max-width: 640px; margin: auto; flex-direction: column; align-items: center; justify-content: center; padding: calc(104px + var(--safe-top)) 28px calc(32px + var(--safe-bottom)); text-align: center; }
.world-mark { position: relative; width: 96px; height: 96px; margin-bottom: 28px; }
.world-mark span { position: absolute; inset: 0; border: 1px solid var(--primary); transform: rotate(45deg); opacity: .3; }
.world-mark span:nth-child(2) { inset: 14px; opacity: .55; }
.world-mark span:nth-child(3) { inset: 29px; background: var(--primary); box-shadow: 0 0 32px rgba(59, 130, 246, .5); opacity: .9; }
.eyebrow { margin: 0 0 8px; color: #93c5fd; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.empty-state h2 { margin: 0; max-width: 560px; font: 600 clamp(34px, 6vw, 62px)/1.04 var(--font-heading); letter-spacing: -.03em; }
.empty-state > p:not(.eyebrow) { max-width: 570px; margin: 20px 0 28px; color: var(--muted); }

.game-view { display: grid; grid-template-rows: minmax(0, 1fr) auto; width: 100%; max-width: 100%; min-width: 0; height: 100%; padding-top: calc(72px + var(--safe-top)); overflow: hidden; }
.story-pane { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.story-scroll { width: 100%; max-width: 100%; height: 100%; min-width: 0; overflow-x: hidden; overflow-y: auto; overflow-anchor: none; overscroll-behavior: contain; scroll-behavior: smooth; padding: 40px max(24px, calc((100% - 780px) / 2)) 36px; }
.latest-button { position: absolute; z-index: 2; right: max(24px, calc((100% - 780px) / 2)); bottom: 16px; display: inline-flex; align-items: center; gap: 7px; min-height: 44px; border: 1px solid #52617a; border-radius: 999px; padding: 9px 15px 9px 12px; background: rgba(24, 34, 52, .96); box-shadow: 0 8px 28px rgba(0, 0, 0, .4); color: #dbeafe; font-size: 13px; font-weight: 650; backdrop-filter: blur(12px); }
.latest-button:hover { border-color: #71829e; background: var(--surface-soft); }
.latest-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.opening-card { max-width: 100%; min-width: 0; margin-bottom: 38px; padding: 22px 24px; border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 4px var(--radius) var(--radius) 4px; background: linear-gradient(135deg, rgba(24, 34, 52, .95), rgba(17, 24, 39, .8)); color: #dbeafe; font-style: italic; white-space: pre-line; overflow-wrap: anywhere; }
.turn { max-width: 100%; min-width: 0; margin: 0 0 44px; overflow-wrap: anywhere; }
.turn-number { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; color: #93c5fd; font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.turn-number::after { content: ""; height: 1px; flex: 1; background: var(--border); }
.turn-delete { display: inline-grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--faint); }
.turn-delete svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.player-action { width: fit-content; max-width: min(88%, 650px); margin: 0 0 20px auto; border: 1px solid rgba(59, 130, 246, .45); border-radius: 14px 4px 14px 14px; padding: 11px 15px 12px; background: rgba(37, 99, 235, .16); color: #dbeafe; }
.player-action-label { display: block; margin-bottom: 3px; color: #93c5fd; font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.player-action p { margin: 0; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.player-action.pending { opacity: .78; }
.turn-pending { margin-bottom: 0; }
.narrative { color: #e8edf5; font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif; font-size: clamp(17px, 2vw, 19px); line-height: 1.82; }
.narrative p { margin: 0 0 1em; }
.turn-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 18px; color: var(--faint); font-size: 12px; }
.thought-card { max-width: 100%; margin: 0 0 32px; border: 1px solid rgba(167, 139, 250, .32); border-radius: var(--radius); padding: 16px 18px; background: rgba(91, 33, 182, .09); overflow-wrap: anywhere; }
.thought-heading { display: flex; align-items: center; gap: 10px; color: #c4b5fd; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.think-basis { border: 1px solid currentColor; border-radius: 999px; padding: 2px 7px; font-size: 9px; letter-spacing: .08em; opacity: .8; }
.think-basis-known { color: #86efac; }.think-basis-inferred { color: #fde68a; }.think-basis-unknown { color: #cbd5e1; }
.thought-question { margin: 10px 0 12px; color: #ddd6fe; font-style: italic; }
.thought-answer { color: #e8edf5; line-height: 1.65; }
.thought-answer p { margin: 0 0 .7em; }.thought-answer p:last-child { margin-bottom: 0; }
.thought-pending { opacity: .82; }
.token-usage { display: inline-flex; align-items: center; gap: 5px; color: #93c5fd; cursor: help; }
.token-usage::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .7; }
.thinking { padding: 20px 0 42px; color: var(--muted); text-align: center; }
.thinking span { display: inline-block; width: 7px; height: 7px; margin: 0 3px; border-radius: 50%; background: var(--primary); animation: pulse 1.15s infinite ease-in-out; }
.thinking span:nth-child(2) { animation-delay: .12s; }.thinking span:nth-child(3) { animation-delay: .24s; }
.thinking p { margin: 10px 0 0; font-size: 13px; }
@keyframes pulse { 0%, 65%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-4px); } }

.play-dock { position: relative; z-index: 4; width: 100%; max-width: 100%; min-width: 0; overflow: visible; border-top: 1px solid var(--border); background: rgba(13, 19, 30, .96); padding: 12px max(24px, calc((100% - 780px) / 2)) calc(12px + var(--safe-bottom)); backdrop-filter: blur(16px); }
.status-strip { display: flex; width: 100%; max-width: 100%; min-width: 0; flex-wrap: wrap; gap: 7px 16px; min-height: 24px; color: var(--muted); font-size: 12px; }
.status-strip span { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.status-strip strong { color: var(--text); font-weight: 600; }
.suggestions { display: flex; width: 100%; max-width: 100%; min-width: 0; gap: 8px; overflow-x: auto; margin: 8px 0; padding-bottom: 2px; scrollbar-width: none; }
.suggestion { min-height: 44px; flex: 0 0 auto; max-width: 280px; border: 1px solid var(--border); border-radius: 22px; padding: 8px 14px; background: var(--surface); color: #dbeafe; font-size: 13px; transition: background-color .2s, border-color .2s, opacity .15s; }
.suggestion:hover { background: var(--surface-raised); border-color: #52617a; }
.action-form { position: relative; width: 100%; max-width: 100%; min-width: 0; }
.action-form label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.action-form textarea { display: block; width: 100%; max-width: 100%; min-width: 0; min-height: 64px; max-height: 180px; resize: vertical; border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 62px 13px 54px; background: var(--surface); color: var(--text); font-size: 16px; line-height: 1.45; transition: border-color .2s, box-shadow .2s; }
.action-form textarea::placeholder { color: var(--faint); }
.action-form textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, .2); outline: 0; }
.send-button { position: absolute; right: 8px; bottom: 8px; display: grid; place-items: center; width: 48px; height: 48px; border: 0; border-radius: 10px; background: var(--primary-strong); color: white; transition: background-color .2s, opacity .15s; }
.send-button:hover:not(:disabled) { background: #1d4ed8; }
.command-trigger { position: absolute; left: 8px; bottom: 8px; display: grid; place-items: center; width: 38px; height: 48px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: #c4b5fd; font: 700 22px/1 var(--font-heading); transition: background-color .2s, border-color .2s; }
.command-trigger:hover:not(:disabled), .command-trigger[aria-expanded="true"] { border-color: rgba(167, 139, 250, .4); background: rgba(91, 33, 182, .2); }
.command-menu { position: absolute; z-index: 8; left: 0; bottom: calc(100% + 9px); width: min(440px, 100%); max-height: min(320px, 42vh); overflow-y: auto; border: 1px solid #4b5870; border-radius: 13px; padding: 7px; background: rgba(17, 24, 39, .98); box-shadow: 0 18px 48px rgba(0, 0, 0, .48); backdrop-filter: blur(16px); }
.command-menu-title { padding: 5px 9px 7px; color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.command-option { display: grid; grid-template-columns: minmax(74px, auto) 1fr; width: 100%; min-height: 54px; gap: 12px; align-items: center; border: 0; border-radius: 9px; padding: 8px 10px; background: transparent; color: var(--text); text-align: left; }
.command-option:hover, .command-option.active { background: var(--surface-soft); }
.command-name { color: #c4b5fd; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; }
.command-description { color: var(--muted); font-size: 12px; line-height: 1.35; }
.image-card { overflow: hidden; }
.scene-image { display: block; width: 100%; max-height: 620px; object-fit: cover; border: 1px solid var(--border); border-radius: 10px; background: #111827; }
.dock-note { margin: 7px 2px 0; color: var(--faint); font-size: 11px; text-align: center; }

dialog { width: min(520px, calc(100% - 28px)); max-height: calc(100dvh - 28px); border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: 0 24px 70px rgba(0,0,0,.55); }
dialog::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(5px); }
.dialog-card { padding: 24px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.dialog-card h2 { margin: 0; font: 600 26px/1.2 var(--font-heading); }
.dialog-card > label { display: block; margin: 15px 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.dialog-card label span { font-weight: 400; }
.dialog-card input, .dialog-card select, .dialog-card textarea { width: 100%; min-height: 48px; border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; background: #0d131e; color: var(--text); font-size: 16px; }
.dialog-card textarea { min-height: 112px; resize: vertical; }
.field-help, .dialog-copy { color: var(--muted); font-size: 13px; }
.field-help { min-height: 40px; margin: 7px 0 0; }
.dialog-copy { margin: 0 0 18px; }
.form-error { padding: 9px 11px; border: 1px solid rgba(248,113,113,.45); border-radius: 8px; background: rgba(127,29,29,.25); color: #fecaca; font-size: 13px; }
.world-dialog { width: min(660px, calc(100% - 28px)); }
.world-dialog .dialog-card { max-height: calc(100dvh - 28px); overflow-y: auto; }
.world-dialog form label { display: block; margin: 0 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.world-settings-button { display: grid; margin: 18px 0 0; color: var(--faint); }
#world-settings-dialog .unfiltered-toggle { display: flex; align-items: center; gap: 11px; margin: 0 0 20px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: rgba(249,115,22,.06); cursor: pointer; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.dialog-actions .button { min-width: 100px; }
.unfiltered-toggle input { width: 20px; min-height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
.unfiltered-toggle input:focus-visible { outline: 0; box-shadow: none; }
.unfiltered-toggle span, .unfiltered-toggle strong, .unfiltered-toggle small { display: block; }
.unfiltered-toggle strong { color: #fed7aa; font-size: 14px; }
.unfiltered-toggle small { margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.45; }
.unfiltered-settings { margin: 0 0 14px; border-left: 2px solid var(--accent); padding-left: 12px; }
.unfiltered-settings a { color: #93c5fd; }
.dialog-card label strong { color: var(--text); }
.world-dialog #world-create-button { margin-top: 18px; }
.world-tag { display: inline-block !important; border: 1px solid rgba(249,115,22,.5); border-radius: 999px; padding: 1px 7px; color: #fed7aa; font-size: 10px; font-weight: 700; vertical-align: 1px; }
.endpoint-button { min-height: 36px; margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; background: transparent; color: #93c5fd; font-size: 12px; }
.world-library-header { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 0 10px; border-top: 1px solid var(--border); padding-top: 20px; }
.world-library-header h3 { margin: 0; font: 600 17px/1.2 var(--font-heading); }
.world-library-header span { color: var(--faint); font-size: 12px; }
.world-library { display: flex; flex-direction: column; gap: 8px; }
.world-library-item { display: flex; align-items: center; gap: 12px; border: 1px solid var(--border); border-radius: 10px; padding: 11px 8px 11px 12px; background: #0d131e; }
.world-library-item > div { flex: 1; min-width: 0; }
.world-library-item strong { display: block; font-size: 14px; }
.world-library-item p { display: -webkit-box; margin: 3px 0 0; overflow: hidden; color: var(--muted); font-size: 12px; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.debug-dialog { width: min(900px, calc(100% - 28px)); }
.debug-dialog .dialog-card { height: min(760px, calc(100dvh - 28px)); display: flex; flex-direction: column; }
.warning { margin: 0 0 12px; padding: 10px 12px; border-left: 3px solid var(--accent); background: rgba(249,115,22,.1); color: #fed7aa; font-size: 13px; }
.debug-dialog pre { flex: 1; min-height: 0; overflow: auto; margin: 0; padding: 16px; border-radius: 10px; background: #070a10; color: #cbd5e1; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(22px + var(--safe-bottom)); max-width: min(520px, calc(100% - 32px)); transform: translateX(-50%); border: 1px solid var(--border); border-radius: 10px; padding: 11px 16px; background: var(--surface-raised); box-shadow: 0 10px 35px rgba(0,0,0,.4); color: var(--text); font-size: 13px; }

@media (max-width: 760px) {
  .app-shell { display: block; width: 100%; max-width: 100%; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); transform: translateX(-102%); transition: transform .22s ease; box-shadow: 20px 0 50px rgba(0,0,0,.4); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-scrim { display: block; }
  .mobile-only { display: inline-grid; }
  .topbar { height: calc(64px + var(--safe-top)); padding-inline: 12px; }
  .game-view { padding-top: calc(64px + var(--safe-top)); }
  .story-scroll { padding: 24px 18px 26px; }
  .latest-button { right: 18px; bottom: 12px; }
  .opening-card { padding: 18px; margin-bottom: 28px; }
  .turn { margin-bottom: 34px; }
  .player-action { max-width: 94%; }
  .turn-pending { margin-bottom: 0; }
  .play-dock { padding: 9px 12px calc(9px + var(--safe-bottom)); }
  .dock-note { display: none; }
  .status-strip { white-space: normal; flex-wrap: wrap; overflow: visible; gap: 3px 12px; line-height: 1.4; }
  input, textarea, select { font-size: 16px !important; }
  .dialog-card { padding: 20px; }

  /* Saat software keyboard terbuka, hanya composer yang tetap di dock.
     Area cerita mengecil di dalam shell, bukan seluruh halaman yang di-pan Safari. */
  body.keyboard-open .play-dock { padding-top: 8px; padding-bottom: max(8px, var(--safe-bottom)); }
  body.keyboard-open .status-strip,
  body.keyboard-open .suggestions,
  body.keyboard-open .dock-note { display: none; }
  body.keyboard-open .action-form textarea { min-height: 56px; max-height: 112px; resize: none; }
}

@media (max-height: 540px) and (orientation: landscape) {
  .topbar { height: calc(56px + var(--safe-top)); }
  .game-view { padding-top: calc(56px + var(--safe-top)); }
  .play-dock { padding-top: 7px; }
  .suggestions, .dock-note { display: none; }
  .action-form textarea { min-height: 54px; }
  .empty-state { padding-top: calc(70px + var(--safe-top)); }
  .world-mark { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
