:root {
  --navy: #12324a;
  --navy-2: #0b2233;
  --blue: #176b87;
  --blue-soft: #e7f2f5;
  --gold: #c59a4a;
  --ink: #17212b;
  --muted: #667785;
  --line: #dce4e8;
  --paper: #f5f7f8;
  --white: #fff;
  --danger: #a83a3a;
  --success: #21734c;
  --radius: 14px;
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; background: var(--paper); }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 0; border-radius: 9px; padding: .78rem 1.2rem; cursor: pointer;
  background: var(--blue); color: #fff; font-weight: 700; line-height: 1.2;
}
button:hover, .button:hover { filter: brightness(.93); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary, .button.secondary { background: var(--navy); }
button.ghost, .button.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
button.danger, .button.danger { background: var(--danger); }
button.small, .button.small { padding: .5rem .8rem; margin-left: auto; }
code { font-family: "Cascadia Mono", Consolas, monospace; }
main { width: min(1160px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 90px; }
.lab-header, .shop-header {
  position: sticky; top: 0; z-index: 20; min-height: 68px; padding: 0 max(24px, calc((100% - 1160px)/2));
  display: flex; align-items: center; gap: 32px; box-shadow: 0 2px 12px #06182514;
}
.lab-header { background: var(--navy-2); color: #fff; }
.lab-brand { color: #fff; font-size: 1.05rem; font-weight: 800; letter-spacing: .03em; }
.lab-header nav, .shop-header nav { display: flex; gap: 8px; }
.lab-header nav a { color: #bdd1dd; padding: .65rem .85rem; border-radius: 8px; }
.lab-header nav a:hover, .lab-header nav a.active { color: #fff; background: #ffffff12; }
.timer { margin-left: auto; min-width: 154px; display: flex; flex-direction: column; align-items: flex-end; justify-content: center; white-space: nowrap; }
.timer span { color: #c8d8e0; font-size: .78rem; font-weight: 700; letter-spacing: .05em; }
.timer strong { margin-left: .35rem; color: #fff; font-family: "Cascadia Mono", Consolas, monospace; font-size: 1.18rem; letter-spacing: 0; }
.timer .timer-message:not(:empty) { color: #ffd2ce; font-size: .68rem; letter-spacing: 0; }
.hero {
  min-height: 355px; padding: 56px; display: grid; grid-template-columns: 1.3fr 1fr; align-items: center; gap: 48px;
  color: #fff; background: linear-gradient(135deg, var(--navy-2), #184c62); border-radius: 20px; overflow: hidden;
  box-shadow: 0 18px 50px #0b22332b;
}
.hero h1 { margin: 8px 0 18px; font-size: clamp(2rem, 4.4vw, 3.6rem); line-height: 1.22; letter-spacing: -.035em; }
.hero p:not(.eyebrow) { color: #cfdee6; line-height: 1.9; max-width: 620px; }
.eyebrow, .shop-kicker { color: var(--gold); font-size: .75rem; font-weight: 800; letter-spacing: .18em; }
.story-map { display: grid; grid-template-columns: repeat(5, auto); align-items: center; gap: 7px; }
.story-map span { display: grid; place-items: center; width: 62px; aspect-ratio: 1; border: 1px solid #ffffff40; border-radius: 50%; background: #ffffff0b; font-weight: 700; }
.story-map b { color: var(--gold); }
.intro-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 28px 0; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: 0 5px 22px #17324308; }
.card h1, .card h2 { margin-top: 0; }
.card p { color: var(--muted); line-height: 1.75; }
.step { display: inline-block; color: var(--gold); font-weight: 900; margin-bottom: 30px; }
.intro-grid h2 { font-size: 1rem; }
.intro-grid p { font-size: .9rem; }
.start-card { display: grid; grid-template-columns: 1fr 1.15fr; gap: 50px; align-items: center; padding: 34px; }
.start-card form, .shop-login form { display: grid; gap: 15px; }
label { display: grid; gap: 7px; font-size: .86rem; font-weight: 700; color: #3c4b55; }
input, select, textarea { width: 100%; padding: .78rem .9rem; border: 1px solid #cbd7dd; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 3px solid #176b8722; border-color: var(--blue); }
.notice { display: flex; align-items: center; gap: 16px; margin: 0 0 20px; padding: 18px 20px; border-left: 4px solid var(--blue); background: var(--blue-soft); border-radius: 8px; }
.notice p { margin: 4px 0 0; }
.notice.error { border-color: var(--danger); background: #fff1f1; }
.notice.success { border-color: var(--success); background: #effaf4; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 28px; margin-bottom: 28px; }
.page-head h1 { margin: 5px 0; font-size: clamp(2rem, 5vw, 3.4rem); letter-spacing: -.04em; }
.page-head p { color: var(--muted); max-width: 720px; line-height: 1.7; }
.score { display: grid; place-items: center; min-width: 130px; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 50%; background: #fff; }
.score strong { font-size: 2.5rem; line-height: .8; }
.score small { font-size: 1rem; color: var(--muted); }
.score span { color: var(--muted); font-size: .78rem; }
.problem-list { display: grid; gap: 16px; }
.problem-card { display: grid; grid-template-columns: 92px 1fr; min-height: 220px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.problem-card.done { border-color: #9acbb1; }
.problem-number { display: grid; place-items: center; background: #eef3f5; color: #aebbc2; font: 800 2rem "Cascadia Mono", Consolas, monospace; }
.done .problem-number { color: #fff; background: var(--success); }
.problem-body { padding: 25px 28px; }
.problem-title { display: flex; align-items: center; gap: 12px; }
.problem-title h2 { margin: 0; font-size: 1.22rem; }
.problem-body > p { color: var(--muted); line-height: 1.7; }
.status { padding: .28rem .6rem; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-size: .72rem; font-weight: 800; }
.done .status { background: #e8f6ee; color: var(--success); }
.metrics { display: flex; flex-wrap: wrap; gap: 9px; margin: 18px 0; }
.metrics span { border: 1px solid var(--line); border-radius: 999px; padding: .32rem .62rem; color: var(--muted); font-size: .74rem; }
.problem-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.flag-form { display: flex; gap: 8px; flex: 1; min-width: 300px; }
.flag-form input { min-width: 180px; }
.finish-row { display: flex; justify-content: space-between; margin-top: 28px; }
.ai-toggle { position: fixed; z-index: 40; right: 22px; bottom: 22px; border-radius: 999px; box-shadow: 0 10px 30px #0b223347; }
.ai-panel { position: fixed; z-index: 50; right: 22px; bottom: 22px; width: min(390px, calc(100vw - 30px)); background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 70px #0b22334a; overflow: hidden; transform: translateY(calc(100% + 40px)); opacity: 0; pointer-events: none; transition: .2s ease; }
.ai-panel.open { transform: none; opacity: 1; pointer-events: auto; }
.ai-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; background: var(--navy-2); color: #fff; }
.ai-head div { display: grid; gap: 3px; }
.ai-head small { color: #b7c9d3; }
.ai-head button { padding: 4px 9px; background: transparent; font-size: 1.35rem; }
.ai-answer { min-height: 116px; padding: 18px; color: #30424d; line-height: 1.7; background: #f6f9fa; }
.ai-panel form { padding: 14px; }
.ai-panel textarea { resize: vertical; min-height: 78px; margin-bottom: 9px; }

/* Believable shop surface */
body.shop { background: #fbfaf7; font-family: "Noto Serif JP", "Yu Mincho", serif; color: #24302f; }
.shop-header { background: #fff; border-bottom: 1px solid #e6e0d6; box-shadow: none; }
.shop-brand { color: #1b4643; font-family: Georgia, serif; font-weight: 800; letter-spacing: .09em; }
.shop-brand span { display: block; font-size: .54rem; letter-spacing: .23em; color: #8a7654; }
.shop-header nav { margin-left: auto; }
.shop-header nav a { padding: .65rem .75rem; color: #4a5957; font-size: .88rem; }
.shop-header .shop-login-link { color: #1b4643; border: 1px solid #bfcac4; border-radius: 5px; font-weight: 700; }
.shop-header .shop-login-state { align-self: center; padding: .45rem .7rem; color: #1b4643; background: #edf5ef; border-radius: 5px; font: 700 .78rem "Noto Sans JP", sans-serif; }
.shop-header .return-link { font-family: "Noto Sans JP", sans-serif; background: #1b4643; color: #fff; border-radius: 5px; }
.shop-header .timer { margin-left: 0; font-family: "Noto Sans JP", sans-serif; }
.shop-header .timer strong { color: #1b4643; }
.shop-header .timer span { color: #61716c; }
.shop-header .timer .timer-message:not(:empty) { color: #a52f2f; }
.shop main { width: min(1240px, calc(100% - 44px)); padding-top: 26px; }
.shop-hero { min-height: 370px; display: flex; flex-direction: column; justify-content: center; padding: 64px; background: linear-gradient(90deg, #103c3aee, #103c3a88), radial-gradient(circle at 80% 30%, #bda777, #705f3e); color: #fff; }
.shop-hero h1 { margin: 10px 0; font-size: clamp(2.5rem, 5vw, 4.6rem); line-height: 1.25; font-weight: 500; letter-spacing: .03em; }
.shop-hero p:last-child { max-width: 530px; color: #e6ece9; line-height: 1.9; }
.shop-notice { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; margin-bottom: 16px; background: #edf5ef; border: 1px solid #c8ddce; font-family: "Noto Sans JP", sans-serif; }
.shop-notice code { color: #153f3b; font-weight: 800; }
.shop-section { padding: 45px 0; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 22px; }
.section-title h2 { font-size: 1.7rem; font-weight: 500; }
.section-title span { color: #87785e; font-size: .84rem; }
.products { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.product { background: #fff; border: 1px solid #e7e0d6; padding-bottom: 18px; }
.product > :not(.product-art) { margin-left: 17px; margin-right: 17px; }
.product-art { height: 190px; background: linear-gradient(135deg, #d8e4df, #859e93); }
.art-2 { background: linear-gradient(135deg, #e9dfcc, #a78a5e); }
.art-3 { background: linear-gradient(135deg, #d8dce4, #7f8aa1); }
.art-4 { background: linear-gradient(135deg, #e0d8d0, #9c7868); }
.category { color: #9b8158; font-size: .7rem; letter-spacing: .14em; }
.product h2 { font-size: 1.05rem; font-weight: 600; }
.product > p:not(.category) { color: #64706d; min-height: 70px; line-height: 1.7; font-size: .84rem; }
.product > div:last-child { display: flex; align-items: center; justify-content: space-between; }
.product button { padding: .5rem .7rem; background: transparent; color: #1b4643; border: 1px solid #bfcac4; border-radius: 2px; font-size: .75rem; }
.product-detail-link { padding: .5rem .7rem; color: #1b4643; border: 1px solid #bfcac4; border-radius: 2px; font: .75rem "Noto Sans JP", sans-serif; }
.product-page { display: grid; grid-template-columns: minmax(300px, .9fr) 1fr; gap: 56px; max-width: 980px; margin: 52px auto; align-items: center; }
.product-detail-art { min-height: 390px; background: linear-gradient(135deg, #d8e4df, #587b70); }
.product-page h1 { font-size: clamp(2rem, 4vw, 3.2rem); font-weight: 500; }
.product-page p:not(.shop-kicker):not(.product-price):not(.muted) { color: #596764; line-height: 1.9; }
.product-price { margin: 20px 0; color: #1b4643; font-size: 1.4rem; font-weight: 700; }
.product-page .muted { margin: 16px 0; }
.shop-login { display: grid; grid-template-columns: 1fr 1fr; gap: 90px; max-width: 980px; margin: 80px auto; padding: 60px; background: #fff; border: 1px solid #e5ddd1; }
.shop-login h1 { font-size: 2.6rem; font-weight: 500; }
.shop-login form { font-family: "Noto Sans JP", sans-serif; }
.muted { color: var(--muted); font-size: .8rem; }
.account-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.outage { max-width: 780px; margin: 70px auto; padding: 48px; text-align: center; background: #fff; border-top: 7px solid #9b3d3d; box-shadow: 0 16px 50px #47252518; }
.outage-code { color: #d8c8c8; font: 900 6rem/1 "Cascadia Mono", monospace; }
.outage h1 { font-size: 2rem; }
.outage > p:not(.eyebrow) { color: #66706f; line-height: 1.8; }
.outage-items { display: grid; gap: 7px; margin: 28px 0; }
.outage-items span { padding: 10px; background: #f7f2f2; color: #7d4545; }
.flag-reveal { display: grid; gap: 8px; margin: 24px 0; padding: 20px; background: #182321; color: #fff; }
.flag-reveal small { color: #a9bbb6; }
.flag-reveal code { font-size: 1.05rem; }

/* Terminal */
.terminal-page { overflow: hidden; }
.terminal-page main { height: calc(100vh - 68px); padding: 16px 0; }
.terminal-wrap { height: 100%; min-height: 420px; display: flex; flex-direction: column; background: #0e1114; border-radius: 10px; overflow: hidden; box-shadow: 0 20px 55px #07141c4d; color: #e5e7e9; font: 15px/1.65 "Cascadia Mono", "SFMono-Regular", Consolas, monospace; }
.terminal-titlebar { height: 46px; display: flex; align-items: center; gap: 20px; padding: 0 16px; background: #262b30; color: #d2d7da; font: 12px "Noto Sans JP", sans-serif; }
.terminal-titlebar > div { display: flex; gap: 7px; }
.terminal-titlebar span { width: 12px; height: 12px; border-radius: 50%; background: #ef6b61; }
.terminal-titlebar span:nth-child(2) { background: #e8bd53; }
.terminal-titlebar span:nth-child(3) { background: #5fbe67; }
.terminal-titlebar strong { margin: auto; font-weight: 500; }
.terminal-titlebar a { color: #c9d9df; }
.terminal-output { flex: 1 1 auto; min-height: 0; overflow: auto; white-space: pre-wrap; padding: 22px; overscroll-behavior: contain; }
.terminal-output .command { color: #b8c7d0; }
.terminal-output .result { color: #e5e7e9; }
.terminal-output .error { color: #ff8d83; }
.terminal-output .masked { color: #9aabb4; }
.terminal-input { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 14px 22px 18px; border-top: 1px solid #ffffff16; background: #0e1114; }
.terminal-input label { display: block; color: #9fc8dd; white-space: nowrap; font: inherit; }
.terminal-input input { flex: 1; border: 0; padding: 0; background: transparent; color: #f3f4f5; border-radius: 0; font: inherit; ime-mode: disabled; }
.terminal-input input:focus { outline: 0; }

/* File viewer and admin */
.file-layout { display: grid; grid-template-columns: 270px 1fr; gap: 20px; }
.file-layout aside { padding: 20px; background: var(--navy-2); border-radius: var(--radius); color: #fff; }
.file-layout aside h2 { font-size: 1rem; }
.file { display: block; padding: 11px; margin: 6px 0; border-radius: 7px; color: #bfd1db; font: .82rem "Cascadia Mono", monospace; }
.file.active, .file:hover { background: #ffffff12; color: #fff; }
.document-view { min-height: 360px; padding: 28px; overflow: auto; background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--gold); border-radius: 8px; white-space: pre-wrap; font: .9rem/1.8 "Cascadia Mono", monospace; }
.admin-tools { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 20px; }
.admin-tools form, .admin-tools div, .export-links { display: flex; gap: 10px; align-items: end; }
.table-wrap { overflow: auto; margin: 12px 0 34px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: #52636d; background: #f3f6f7; white-space: nowrap; }
td code { font-size: .74rem; }

@media (max-width: 900px) {
  main, .shop main { width: min(100% - 24px, 720px); padding-top: 24px; }
  .hero, .start-card, .shop-login { grid-template-columns: 1fr; padding: 34px; }
  .story-map { display: none; }
  .intro-grid, .products { grid-template-columns: 1fr 1fr; }
  .shop-header nav a:not(.return-link), .lab-header nav { display: none; }
  .problem-card { grid-template-columns: 58px 1fr; }
  .file-layout { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .lab-header, .shop-header { padding: 0 12px; gap: 10px; }
  .timer { min-width: 80px; }
  .intro-grid, .products, .account-grid { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
  .score { min-width: 90px; }
  .problem-card { grid-template-columns: 1fr; }
  .problem-number { min-height: 48px; }
  .problem-body { padding: 20px; }
  .flag-form { min-width: 100%; flex-direction: column; }
  .shop-hero { padding: 36px 24px; }
  .shop-login { margin: 20px auto; padding: 25px; gap: 30px; }
  .product-page { grid-template-columns: 1fr; gap: 24px; margin: 20px auto; }
  .product-detail-art { min-height: 240px; }
  .admin-tools, .admin-tools form { align-items: stretch; flex-direction: column; }
}
