:root {
  color-scheme: dark;
  --bg: #201813;
  --text: #fff4e6;
  --muted: #d8c8b7;
  --accent: #f2ba81;
  --line: #f9d8b535;
  --panel: #261d17;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: .5; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid #ffcc96; outline-offset: 4px; }
[hidden] { display: none !important; }

#hearth {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100svh;
  overflow: hidden;
  overflow: clip;
  isolation: isolate;
  background: #33251d;
}
#stage { position: absolute; z-index: -3; top: 0; left: 0; pointer-events: none; }
#stage img, #stage canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
#stage img { object-fit: fill; }
.vignette {
  position: absolute;
  inset: 0;
  z-index: -2;
  background: linear-gradient(90deg, #120b08bd 0%, #120b085e 30%, transparent 60%),
    linear-gradient(0deg, #120b08ad, transparent 24%, transparent 79%, #120b0882);
  pointer-events: none;
}
.topbar { display: flex; grid-row: 1; justify-content: space-between; align-items: center; z-index: 1; padding: clamp(14px, 2.2vw, 30px); gap: 14px; }
.corner-title h1 { margin: 0; font: 500 clamp(.96rem, 1.8vw, 1.3rem)/1.15 Georgia, serif; text-shadow: 0 1px 7px #120b08; }
.brand { display: inline-block; margin-top: .2rem; text-decoration: none; color: #ffe0bd; font-size: .75rem; font-weight: 650; text-shadow: 0 1px 7px #120b08; }
.brand:hover { text-decoration: underline; }
.top-actions { display: flex; gap: 8px; }
.glass, .subtle, .primary, .quick-times button, .preset-list button {
  display: inline-flex; align-items: center; justify-content: center; gap: .48rem;
  min-height: 42px; padding: .53rem .85rem; border: 1px solid var(--line); border-radius: 10px;
  font-size: .9rem; font-weight: 650; background: #342820;
}
.glass { background: #201813d9; backdrop-filter: blur(12px); }
.glass:hover, .subtle:hover, .quick-times button:hover, .preset-list button:hover { background: #4f392a; }
.icon-only { min-width: 42px; padding-inline: .58rem; }
.icon {
  display: inline-block; vertical-align: middle; width: 1.15rem; height: 1.15rem;
  fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round;
}
.controls { grid-row: 3; justify-self: center; padding: 12px 12px max(18px, env(safe-area-inset-bottom)); z-index: 2; }
.controlbar {
  display: flex; padding: 5px; gap: 4px; background: #211814ec; border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 12px 30px #130b0870; backdrop-filter: blur(12px);
}
.controlbar button {
  background: transparent; border: 0; min-height: 49px; border-radius: 12px;
  padding: 0 clamp(.5rem, 1.5vw, 1.05rem); font-weight: 650; font-size: .9rem; color: var(--text);
  display: flex; align-items: center; justify-content: center; gap: .52rem;
}
.controlbar button:hover { background: #4b3428; }
.controlbar .icon { color: var(--accent); }
.woodpile {
  z-index: 1; position: absolute; left: var(--wood-x, 82%); top: var(--wood-y, 74%);
  transform: translate(-50%, -50%); min-height: 48px; min-width: 48px;
  padding: 6px 10px 6px 7px; display: flex; align-items: center; gap: 6px;
  border: 1px solid #ffddae75; border-radius: 30px; background: #211814dc;
  color: #ffebd4; white-space: nowrap; box-shadow: 0 3px 14px #160b0599; font-size: .82rem; font-weight: 650;
}
.woodpile:hover { background: #503625; border-color: #ffddae; }
.wood-dot { display: grid; place-items: center; min-width: 24px; height: 24px; border-radius: 50%; background: #f2ba81; color: #2c190e; }
.wood-dot .icon { width: .94rem; height: .94rem; stroke-width: 2; }
.wood-count { padding: .24em .45em; border-radius: 10px; background: #f2ba8126; font-size: .78rem; font-variant-numeric: tabular-nums; }
.woodpile[aria-disabled="true"] { cursor: default; }
.woodpile[aria-disabled="true"]:hover { background: #211814dc; border-color: #ffddae75; }
.woodpile[aria-disabled="true"] .wood-dot { background: #624633; color: #ffe3c7; }

.class-display {
  position: absolute; top: 50%; left: clamp(18px, 5.7vw, 94px); transform: translateY(-43%);
  z-index: 1; width: min(44vw, 650px); display: grid; gap: clamp(14px, 2.6vh, 30px);
  padding: clamp(17px, 2.6vw, 36px); border: 1px solid var(--line); border-radius: 22px;
  background: #201813e8; backdrop-filter: blur(8px);
}
#class-note {
  position: relative; margin: 0; padding: .08em 1.35rem .12em 0; border: 0; background: transparent; text-align: left;
  color: var(--text); font-size: clamp(1.25rem, 3.6vw, 3.9rem); line-height: 1.17; font-weight: 650;
  overflow-wrap: anywhere; max-height: 42svh; overflow: auto;
}
#class-note-text { white-space: pre-wrap; }
#class-note:is(:hover, :focus-visible) { color: #ffe0bd; }
.note-edit-icon { position: absolute; top: .1em; right: 0; display: inline-flex; color: var(--accent); opacity: 0; }
#class-note:is(:hover, :focus-visible) .note-edit-icon { opacity: 1; }
#hearth.zoomed .class-display {
  top: auto; bottom: max(85px, 12svh); left: clamp(14px, 2.2vw, 32px);
  width: min(32vw, 430px); padding: clamp(12px, 1.6vw, 22px); transform: none;
}
#hearth.zoomed #class-note { font-size: clamp(1.15rem, 2.6vw, 2.8rem); }
#hearth.zoomed #timer-clock { font-size: clamp(2.3rem, 4.7vw, 4.8rem); }
#timer-clock { font-size: clamp(2.6rem, 7.1vw, 7.6rem); font-variant-numeric: tabular-nums; font-weight: 650; line-height: 1.07; letter-spacing: -.05em; }
#timer-track { height: clamp(10px, 1.8vh, 18px); overflow: hidden; background: #584030; border-radius: 20px; }
#timer-progress { height: 100%; background: #f2ba81; width: 100%; transition: width .25s linear; border-radius: inherit; }
#timer-caption { color: var(--accent); font-weight: 650; }
#timer-caption:empty { display: none; }
#timer-display:has(#timer-track:not([hidden])) #timer-caption:not(:empty) { margin-top: .6rem; }
.project-controls {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); z-index: 3;
  display: none; gap: 8px;
}
#hearth.projecting .brand, #hearth.projecting .top-actions, #hearth.projecting .controls { visibility: hidden; }
#hearth.projecting .corner-title h1 { color: #ffe6cde0; font-size: .96rem; }
#hearth.projecting .vignette { opacity: .22; }
#hearth.projecting .project-controls { display: flex; opacity: .28; transition: opacity .2s; }
#hearth.projecting .project-controls:is(:hover, :focus-within) { opacity: 1; }
#hearth.projecting .woodpile:not(:hover, :focus-visible, .low) { opacity: .58; }
#hearth.projecting:not(.zoomed) .class-display { transform: translateY(-50%); }
#hearth.still #timer-progress { transition: none; }

dialog { 
  margin: auto auto max(83px, 11vh); padding: 0; width: min(510px, calc(100% - 24px));
  max-height: calc(100dvh - max(100px, 13vh)); overflow: auto; border: 1px solid #8d6a50;
  border-radius: 18px; background: var(--panel); color: var(--text); box-shadow: 0 18px 90px #140a08d9;
}
dialog::backdrop { background: #140e0a51; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 18px 11px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font: 500 1.75rem Georgia, serif; }
.panel-content { display: grid; gap: 12px; padding: 16px 18px 19px; }
.scene-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scene-card {
  position: relative; min-height: 90px; min-height: clamp(82px, 14vh, 117px); overflow: hidden;
  border-radius: 10px; border: 1px solid var(--line); text-align: left; font-weight: 700;
  display: flex; align-items: end; padding: 9px; isolation: isolate; background: #463428;
}
.scene-card img { position: absolute; z-index: -2; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scene-card::after { content: ""; position: absolute; z-index: -1; inset: 0; background: linear-gradient(0deg, #180f0cf2, transparent 80%); }
.scene-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: #ffddae; }
.scene-card:hover { border-color: #fff4e6; }
.field { display: grid; align-items: center; gap: 12px; color: var(--text); font-size: .95rem; }
.field.compact, .field.audio-row { grid-template-columns: 1fr minmax(135px, 50%); }
.field.stacked { gap: 7px; }
input:not([type="range"]):not([type="checkbox"]), select, textarea {
  min-width: 0; width: 100%; padding: 9px 11px; border: 1px solid #765642; border-radius: 8px;
  color: var(--text); background-color: #352820;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: #cbb8a7; }
input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { width: 20px; height: 20px; margin: 0; }
input[type="range"] { width: 100%; margin: 1px 0; min-height: 24px; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.primary { background: var(--accent); color: #2e1c10; border-color: transparent; }
.primary:hover { background: #ffcea0; }
.wide { width: 100%; }
.actions, .quick-times { display: flex; gap: 8px; flex-wrap: wrap; }
.actions input { flex: 1 1 135px; }
.quick-times button { flex: 1; min-width: 48px; }
.quick-times button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.fine { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.4; }
.fine.help { margin: -5px 0 3px 30px; }
.panel-content h3 { margin: .2rem 0 0; font-size: .97rem; }
.preset-list { display: grid; gap: 6px; }
.preset-row { display: flex; gap: 6px; }
.preset-row > :first-child { flex: 1; justify-content: start; text-align: left; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.no-script { position: absolute; bottom: 1rem; background: var(--panel); padding: .5rem 1rem; }

@media (max-width: 640px) {
  .controlbar { gap: 1px; }
  .controlbar button { flex-direction: column; gap: .18rem; padding: .3rem clamp(7px, 2vw, 16px); font-size: .75rem; }
  .topbar { gap: 8px; }
  .top-actions button { min-height: 40px; font-size: .78rem; }
  .brand { font-size: .73rem; max-width: 120px; }
  .class-display { top: 19%; transform: none; width: min(86vw, 470px); }
  #hearth.projecting:not(.zoomed) .class-display { transform: none; }
  #hearth.zoomed .class-display { top: 15%; bottom: auto; width: min(86vw, 430px); }
  #class-note { max-height: 32svh; }
}
@media (max-width: 480px) {
  .top-actions { gap: 5px; }
  .top-actions button { width: 40px; padding-inline: 0; }
  .top-actions button > span:nth-child(2) { display: none; }
}
@media (max-height: 450px) {
  .topbar { padding-block: 8px; }
  .controls { padding-bottom: 8px; }
  .class-display { padding-block: 10px; gap: 8px; }
  #timer-clock { font-size: 14vh; }
  dialog { margin-bottom: 10px; max-height: calc(100dvh - 20px); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0s !important; } }
.woodpile::before { content: ""; position: absolute; inset: -17px -19px; border-radius: inherit; }
@media (max-width: 640px) {
  .woodpile::before { inset: -8px; }
}
