:root {
  --paper: #f6ecd9;
  --ink: #2b1d12;
  --wood: #8b5a2b;
  --accent: #d9822b;
  --green: #4caf50;
  --red: #e53935;
  --panel: rgba(30, 20, 12, 0.88);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a120b; font-family: Georgia, 'Times New Roman', serif; color: var(--paper); }
#game { position: fixed; inset: 0; }
#game canvas { display: block; cursor: crosshair; }
[hidden] { display: none !important; }

/* buttons */
.btn {
  font: 600 15px/1 system-ui, sans-serif; padding: 10px 16px; border-radius: 8px; cursor: pointer;
  background: #f3e3c4; color: var(--ink); border: 2px solid #6b4423; box-shadow: 0 3px 0 #6b4423;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #6b4423; }
.btn.primary { background: var(--accent); color: #fff; border-color: #8a4b12; box-shadow: 0 3px 0 #8a4b12; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--paper); border-color: rgba(246,236,217,0.4); box-shadow: none; }

/* HUD */
#hud {
  position: fixed; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; gap: 18px;
  background: var(--panel); padding: 10px 16px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.08);
  font-family: system-ui, sans-serif;
}
#hud .stat { display: flex; flex-direction: column; }
#hud .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.6; }
#money { font-size: 22px; font-weight: 700; color: #9be29e; }
#rep { font-size: 18px; color: #f4c542; letter-spacing: 2px; }
#hud nav { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }

/* step panel */
#step {
  position: fixed; top: 12px; left: 12px; width: 470px; max-width: calc(100vw - 24px);
  background: var(--panel); border-radius: 12px; padding: 14px 16px; font-family: system-ui, sans-serif;
  border: 1px solid rgba(255,255,255,0.08); user-select: none;
}
.step-head { display: flex; justify-content: space-between; align-items: center; }
.job-name { font: 700 18px Georgia, serif; color: #f4c542; }
.step-count { font-size: 13px; opacity: 0.75; margin: 4px 0 8px; }
.step-instr { font-size: 15px; line-height: 1.4; margin-bottom: 10px; }
.step-instr b { color: #ffd28a; }
.step-panel { position: relative; }
.keys { font-size: 12.5px; opacity: 0.8; margin-top: 8px; line-height: 1.5; }
kbd { background: #f3e3c4; color: var(--ink); border-radius: 4px; padding: 1px 5px; font-size: 11px; border-bottom: 2px solid #8a6a45; }

/* meters */
.meter { margin: 6px 0; }
.meter-label { font-size: 12px; opacity: 0.8; margin-bottom: 3px; }
.meter-track { position: relative; height: 16px; background: #3a2a1d; border-radius: 8px; overflow: hidden; border: 1px solid #5a4630; }
.meter-zone { position: absolute; top: 0; bottom: 0; opacity: 0.85; }
.meter-needle { position: absolute; top: -2px; bottom: -2px; width: 4px; margin-left: -2px; background: #fff; box-shadow: 0 0 6px #fff; border-radius: 2px; }

/* loupe */
.loupe-wrap { display: flex; flex-direction: column; align-items: center; }
.loupe { width: 100%; max-width: 420px; border-radius: 8px; border: 3px solid #333; box-shadow: inset 0 0 20px rgba(0,0,0,0.3); }
.loupe-read { margin-top: 6px; font: 700 16px system-ui; color: #ffd28a; }
.hint-toggle { display: block; font-size: 13px; margin-top: 8px; opacity: 0.85; cursor: pointer; }

/* flash text */
.flash { position: absolute; left: 50%; top: -6px; transform: translateX(-50%); padding: 6px 12px; border-radius: 8px; font-weight: 700; font-size: 14px; white-space: nowrap; animation: pop 1.4s forwards; pointer-events: none; z-index: 3; }
.flash-good { background: var(--green); color: #fff; }
.flash-bad { background: var(--red); color: #fff; }
.flash-info { background: #f3e3c4; color: var(--ink); }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 8px) scale(0.9); } 12% { opacity: 1; transform: translate(-50%, -10px) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -24px); } }

/* modal */
#modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(10, 6, 3, 0.45); padding: 16px; z-index: 10; }
.card {
  background: var(--paper); color: var(--ink); border-radius: 14px; padding: 24px 28px; max-width: 520px; width: 100%;
  max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  background-image: repeating-linear-gradient(0deg, transparent 0 27px, rgba(120, 90, 50, 0.08) 27px 28px);
  border: 1px solid #d9c49c;
}
.card.wide { max-width: 760px; }
.card h1.title { font-size: 44px; margin: 0 0 6px; text-align: center; color: #6b3a14; }
.card h2 { margin: 0 0 8px; color: #6b3a14; }
.card h3 { margin: 14px 0 6px; }
.card p { line-height: 1.55; }
.sub { opacity: 0.75; margin-top: 0; text-align: center; }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.letter { font-family: 'Segoe Script', 'Bradley Hand', 'Comic Sans MS', cursive; font-size: 17px; line-height: 1.75; white-space: normal; padding: 6px; }
.kicker { font: 700 12px system-ui; text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); }
.controls { background: #ead8b4; border-radius: 8px; padding: 10px 12px; font-family: system-ui, sans-serif; font-size: 14px; line-height: 1.5; margin-top: 12px; }
.client { font: 13px system-ui; opacity: 0.7; }
.plan { line-height: 1.7; padding-left: 22px; }

.jobs { display: flex; flex-direction: column; gap: 10px; }
.job { display: flex; gap: 14px; align-items: center; background: rgba(255,255,255,0.55); border: 1px solid #d9c49c; border-radius: 10px; padding: 12px 14px; }
.job.locked { opacity: 0.6; }
.job.owned { opacity: 0.7; }
.job-main { flex: 1; }
.job h3 { margin: 0 0 2px; font-size: 18px; }
.job p { margin: 6px 0; font-size: 14.5px; }
.need { display: inline-block; font: 600 12px system-ui; background: #f3d1c4; color: #8a2b12; border-radius: 6px; padding: 3px 8px; margin-right: 6px; }
.done { font: 600 12px system-ui; color: #2e7d32; margin-left: 6px; }
.price { font: 700 15px system-ui; color: #2e7d32; margin-left: 8px; }
.effect { font: 600 13px system-ui; color: #8a4b12; }

.result { text-align: center; }
.result p { text-align: left; }
.score { font: 800 56px system-ui; margin: 6px 0 0; }
.score.a { color: #2e7d32; } .score.b { color: #558b2f; } .score.c { color: #c77700; } .score.d { color: #c62828; }
.pay { font: 800 28px system-ui; color: #2e7d32; text-align: center !important; }

.quiz-q { font-size: 16px; line-height: 1.45; margin: 4px 0 10px; }
.quiz-a { display: flex; flex-direction: column; gap: 8px; }
.quiz-btn { text-align: left; }
.quiz-btn.right { background: var(--green); color: #fff; border-color: #2e7d32; opacity: 1; }
.quiz-btn.wrong { background: var(--red); color: #fff; border-color: #a12020; opacity: 1; }

.tabs { display: flex; gap: 8px; margin: 8px 0 12px; }
.tab.active { background: var(--accent); color: #fff; }
.lesson { border-left: 4px solid var(--accent); padding-left: 12px; margin-bottom: 14px; }
.lesson h3 { margin-top: 0; }
.tools li { margin-bottom: 8px; line-height: 1.45; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 30px); background: var(--panel); color: var(--paper); padding: 12px 18px; border-radius: 10px; font: 15px system-ui; opacity: 0; transition: 0.3s; pointer-events: none; max-width: 90vw; text-align: center; z-index: 20; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 700px) {
  #hud { flex-wrap: wrap; }
  #step { width: auto; right: 12px; }
  .card { padding: 18px; }
}
