:root {
  --paper: #f5f2ea;
  --ink: #111111;
  --soft-ink: #3d3d3d;
  --muted: #77716a;
  --line: #d8d1c6;
  --panel: #fffdf8;
  --wash: #ebe5db;
  --deep: #0f0f0f;
  --radius: 10px;
  --shadow: 0 18px 48px rgba(20, 18, 15, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 42px 42px;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: manipulation;
}

body.practice-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--paper);
  transition: opacity 360ms ease, visibility 360ms ease;
}

.splash.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-card {
  width: min(720px, 100%);
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--panel);
  padding: clamp(22px, 5vw, 48px);
  box-shadow: var(--shadow);
}

.splash-mark {
  width: 100%;
  height: 120px;
  margin-bottom: 18px;
}

.splash-line {
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 700;
  stroke-dashoffset: 700;
  animation: drawIn 1.6s ease forwards;
}

@keyframes drawIn {
  to { stroke-dashoffset: 0; }
}

.splash h1,
.brand h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.2rem, 8vw, 5.4rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.splash p {
  max-width: 58ch;
  color: var(--soft-ink);
  font-size: 1.05rem;
  line-height: 1.55;
}

.splash-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.primary {
  background: var(--ink);
  color: var(--paper);
}

.app-shell {
  width: min(1440px, calc(100vw - 20px));
  min-height: 100vh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 0 20px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 2px solid var(--ink);
  border-radius: 0 0 14px 14px;
  background: rgba(245, 242, 234, 0.92);
  padding: 10px;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
}

.brand h1 {
  font-size: clamp(1.25rem, 4vw, 2rem);
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--panel);
  padding: 0 12px;
  font-size: 0.86rem;
  font-weight: 800;
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.82fr) minmax(420px, 1.35fr) minmax(260px, 0.82fr);
  gap: 12px;
  margin-top: 12px;
}

.panel {
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  border-bottom: 2px solid var(--ink);
  background: var(--wash);
  padding: 10px 12px;
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel-body {
  padding: 12px;
}

.story {
  display: grid;
  gap: 12px;
}

.story-card {
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
}

.story-card h2 {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 4vw, 2.7rem);
  line-height: 1;
}

.story-card p {
  margin: 0;
  color: var(--soft-ink);
  line-height: 1.52;
}

.task-list {
  display: grid;
  gap: 8px;
}

.task {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 9px;
  align-items: start;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--panel);
}

.task.done {
  border-color: var(--ink);
  background:
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.035) 0 8px, transparent 8px 16px),
    var(--panel);
}

.task-dot {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  font-weight: 900;
}

.task strong {
  display: block;
}

.task span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.studio {
  display: grid;
  gap: 10px;
}

.prompt-strip {
  display: grid;
  gap: 6px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--deep);
  color: var(--paper);
  padding: 12px;
}

.prompt-strip strong {
  font-size: 1rem;
}

.prompt-strip span {
  color: #d8d1c6;
  line-height: 1.35;
}

.canvas-frame {
  position: relative;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

canvas {
  display: block;
  width: 100%;
  height: min(62vh, 620px);
  min-height: 420px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    #fffefa;
  background-size: 32px 32px;
  touch-action: none;
}

.ghost-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.guide-line,
.guide-shape {
  position: absolute;
  border-color: rgba(0, 0, 0, 0.28);
}

.guide-line {
  height: 0;
  border-top: 3px dashed rgba(0, 0, 0, 0.28);
  transform-origin: left center;
}

.guide-shape {
  border: 3px dashed rgba(0, 0, 0, 0.28);
}

.toolrow {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.toolrow button.active,
.pressure-group button.active {
  background: var(--ink);
  color: var(--paper);
}

.toolrow button.locked {
  opacity: 0.42;
  background:
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.05) 0 6px, transparent 6px 12px),
    var(--panel);
}

.draw-settings {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(240px, 1fr);
  gap: 8px;
  align-items: stretch;
}

.draw-settings label,
.pressure-group {
  display: grid;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 8px;
}

.draw-settings label {
  grid-template-columns: auto 1fr auto;
  gap: 8px;
}

.draw-settings span,
.draw-settings strong {
  font-size: 0.82rem;
}

.draw-settings input {
  width: 100%;
  accent-color: var(--ink);
}

.pressure-group {
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.pressure-group button {
  min-height: 34px;
  border-width: 1px;
  font-size: 0.78rem;
}

#stylusChip.pen {
  background: var(--ink);
  color: var(--paper);
}

#stylusChip.touch {
  background: var(--wash);
}

.feedback {
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px;
  color: var(--soft-ink);
  line-height: 1.4;
}

.meter {
  height: 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  background: var(--panel);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--ink);
  transition: width 220ms ease;
}

.quiz {
  display: none;
  gap: 10px;
}

.quiz.active {
  display: grid;
}

.quiz h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.choice.correct {
  background: var(--ink);
  color: var(--paper);
}

.choice.wrong {
  background: #e9ded2;
}

.inventory {
  display: grid;
  gap: 8px;
}

.masterwork {
  display: grid;
  gap: 8px;
}

.masterwork canvas {
  width: 100%;
  height: auto;
  min-height: 0;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 34%, rgba(0, 0, 0, 0.04), transparent 18%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    #fffefa;
  background-size: auto, 28px 28px, 28px 28px;
}

.masterwork p {
  min-height: 44px;
  margin: 0;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 9px;
  color: var(--soft-ink);
  font-size: 0.86rem;
  line-height: 1.35;
}

.inventory-item,
.fact-card {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px;
}

.inventory-item strong,
.fact-card strong {
  display: block;
}

.inventory-item span,
.fact-card p {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.level-map {
  display: grid;
  gap: 8px;
}

.level-card {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px;
}

.level-card.current {
  border-color: var(--ink);
}

.level-card.locked {
  opacity: 0.55;
}

.level-card.soon {
  background:
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.028) 0 8px, transparent 8px 16px),
    var(--panel);
}

.level-card button {
  width: 100%;
  margin-top: 8px;
}

.footer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.practice-workspace {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 42px 42px;
}

.practice-workspace.open,
.copy-workspace.open {
  display: grid;
}

.copy-workspace {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: none;
  grid-template-rows: auto 1fr auto;
  background: var(--paper);
}

.practice-topbar,
.practice-toolbar {
  display: grid;
  gap: 10px;
  border: 2px solid var(--ink);
  background: rgba(245, 242, 234, 0.95);
  padding: 10px;
  backdrop-filter: blur(14px);
}

.practice-topbar {
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: center;
  border-width: 0 0 2px;
}

.practice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.practice-stage {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 14px;
}

#practiceCanvas {
  display: block;
  width: min(100%, 1500px);
  height: 100%;
  min-height: 0;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    #fffefa;
  background-size: 32px 32px;
  box-shadow: var(--shadow);
  touch-action: none;
}

.practice-hint {
  position: absolute;
  top: 24px;
  left: 24px;
  display: grid;
  gap: 3px;
  max-width: min(360px, calc(100vw - 48px));
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.9);
  padding: 10px;
  pointer-events: none;
}

.practice-hint span {
  color: var(--muted);
  font-size: 0.84rem;
}

.practice-toolbar {
  grid-template-columns: minmax(320px, 1.1fr) minmax(280px, 0.9fr) minmax(260px, 0.7fr);
  align-items: center;
  border-width: 2px 0 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.practice-tool-group,
.practice-pressure {
  display: grid;
  gap: 8px;
}

.practice-tool-group {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.practice-pressure {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.practice-sliders {
  display: grid;
  gap: 8px;
}

.practice-sliders label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 8px;
}

.practice-sliders input {
  width: 100%;
  accent-color: var(--ink);
}

.practice-toolbar button.active {
  background: var(--ink);
  color: var(--paper);
}

.practice-toolbar button.locked {
  opacity: 0.42;
  background:
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.05) 0 6px, transparent 6px 12px),
    var(--panel);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}

.copy-stage {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(320px, 1.2fr) minmax(220px, 0.7fr);
  gap: 10px;
  min-height: 0;
  padding: 10px;
}

.copy-reference,
.copy-drawing,
.copy-portfolio {
  min-height: 0;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.94);
  overflow: hidden;
}

.reference-frame,
.copy-canvas-frame {
  position: relative;
  height: calc(100% - 54px);
  min-height: 300px;
  display: grid;
  place-items: center;
  padding: 10px;
}

#referenceCanvas,
#copyCanvas,
#traceCanvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: #fffefa;
  touch-action: none;
}

#traceCanvas {
  position: absolute;
  inset: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  pointer-events: none;
  opacity: 0.25;
  mix-blend-mode: multiply;
}

#referenceEmpty {
  position: absolute;
  inset: auto 18px 18px;
  margin: 0;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.9);
  padding: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  pointer-events: none;
}

.copy-canvas-frame.mirrored {
  transform: scaleX(-1);
}

.copy-canvas-frame.mirrored #copyCanvas,
.copy-canvas-frame.mirrored #traceCanvas {
  transform: scaleX(-1);
}

.portfolio-list {
  display: grid;
  gap: 8px;
  max-height: calc(100% - 54px);
  overflow: auto;
  padding: 10px;
}

.portfolio-card {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 8px;
}

.portfolio-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.portfolio-card strong {
  display: block;
  margin-top: 6px;
  font-size: 0.82rem;
}

@media (max-width: 1060px) {
  .game-grid {
    grid-template-columns: 1fr;
  }

  .studio-panel {
    grid-row: 1;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100vw - 10px, 680px);
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .hud {
    justify-content: stretch;
  }

  .chip {
    flex: 1;
    justify-content: center;
  }

  .toolrow,
  .choice-grid {
    grid-template-columns: 1fr 1fr;
  }

  .draw-settings {
    grid-template-columns: 1fr;
  }

  canvas {
    height: 56vh;
    min-height: 360px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .practice-topbar,
  .practice-toolbar {
    grid-template-columns: 1fr;
  }

  .practice-actions {
    justify-content: stretch;
  }

  .practice-actions button,
  .practice-actions .chip {
    flex: 1;
    justify-content: center;
  }

  .practice-tool-group {
    grid-template-columns: repeat(3, 1fr);
  }

  .practice-pressure {
    grid-template-columns: repeat(2, 1fr);
  }

  .practice-stage {
    padding: 8px;
  }

  .practice-hint {
    display: none;
  }

  .copy-stage {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .reference-frame,
  .copy-canvas-frame {
    height: 48vh;
  }
}
