:root {
    color-scheme: light;
    --navy: #101f40;
    --deep: #08152e;
    --blue: #254e93;
    --blue-soft: #eaf0fb;
    --paper: #f3f6fb;
    --ink: #152644;
    --muted: #5a6b88;
    --border: #dde5f1;
    --gold: #f5ca79;
    --gold-deep: #c8912f;
    --danger: #b3362f;
    --ok: #1f7a4d;
    --radius: 20px;
    --shadow-sm: 0 2px 6px #1a325912, 0 1px 2px #1a32590d;
    --shadow-md: 0 14px 34px #19396e26;
    font-family: "Leelawadee UI", "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
    background:
        radial-gradient(circle at 0 0, #dfe8f8 0, transparent 420px),
        var(--paper);
    color: var(--ink);
    line-height: 1.65;
}
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--gold-deep); outline-offset: 3px; border-radius: 6px; }
h1, h2, p { margin: 0; }
h2 { font-size: 1.15rem; line-height: 1.45; }
.wrap { width: min(1240px, calc(100% - 56px)); margin-inline: auto; }

/* ---------- icons ---------- */
.icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -.22em; }

/* ---------- header ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #08152ef2;
    color: #fff;
    border-bottom: 1px solid #ffffff1a;
    box-shadow: 0 4px 18px #08152e40;
}
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; min-height: 72px; padding-block: 10px; }
.brand { display: inline-flex; gap: 12px; align-items: center; color: #fff; text-decoration: none; min-width: 0; }
.brand-mark {
    display: grid; place-items: center; flex: none;
    width: 44px; height: 44px; border-radius: 13px;
    background: linear-gradient(140deg, #f8d998, var(--gold-deep));
    color: var(--deep);
    box-shadow: 0 4px 14px #f5ca7940;
}
.brand-mark .icon { width: 26px; height: 26px; }
.brand-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.3; min-width: 0; }
.brand-text small { font-weight: 400; font-size: .78rem; color: #b9c9e6; }
.main-nav { display: flex; gap: 6px; background: #ffffff0d; padding: 5px; border-radius: 14px; border: 1px solid #ffffff14; }
.main-nav a {
    display: inline-flex; align-items: center; gap: 8px;
    min-height: 44px; padding: 8px 16px; border-radius: 10px;
    font-size: .95rem; font-weight: 600; text-decoration: none; color: #d4e0f6;
    transition: background .15s ease, color .15s ease;
}
.main-nav a:hover { background: #ffffff17; color: #fff; }
.main-nav a[aria-current="page"] { background: var(--gold); color: var(--deep); }
.main-nav .icon { width: 20px; height: 20px; }

/* ---------- layout ---------- */
main { flex: 1; padding-block: 28px 56px; }

/* ---------- hero ---------- */
.hero {
    position: relative;
    overflow: hidden;
    display: grid;
    align-items: center;
    gap: clamp(20px, 5vw, 64px);
    margin-bottom: 28px;
    padding: clamp(28px, 5.5vw, 70px);
    border-radius: 28px;
    color: #fff;
    background:
        radial-gradient(ellipse at 88% 18%, #3d74d29c, transparent 55%),
        radial-gradient(ellipse at 8% 110%, #f5ca7930, transparent 45%),
        repeating-linear-gradient(135deg, transparent 0 26px, #ffffff08 27px 28px),
        linear-gradient(118deg, #0b1834, #172f5e 58%, #23498a);
    box-shadow: 0 20px 44px #172e5b2e;
}
.presentation-hero { grid-template-columns: minmax(0, 1fr) auto; }
.eyebrow {
    display: inline-flex; align-items: center; gap: 8px;
    margin-bottom: 14px; padding: 6px 14px; border-radius: 999px;
    background: #ffffff14; border: 1px solid #ffffff26;
    color: var(--gold); font-size: .9rem; font-weight: 600;
}
.hero h1 { font-size: clamp(2rem, 5vw, 4.3rem); line-height: 1.15; overflow-wrap: anywhere; }
.hero h1 span { display: block; margin-top: 8px; color: var(--gold); font-size: .68em; line-height: 1.25; }
.hero p { margin-top: 14px; color: #dde8fb; font-size: clamp(.98rem, 1.6vw, 1.15rem); }
.hero-chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 0; padding: 0; list-style: none; }
.hero-chips li {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 14px; border-radius: 12px;
    background: #ffffff12; border: 1px solid #ffffff22;
    font-size: .92rem; color: #eef3fd;
}
.hero-chips .icon { color: var(--gold); }
.school-logo {
    width: clamp(110px, 17vw, 210px);
    aspect-ratio: 1;
    object-fit: contain;
    padding: 12%;
    border-radius: 26%;
    background: #fff;
    box-shadow: 0 0 0 8px #ffffff1f, 0 14px 40px #09193266;
}
.presentation-hero .school-logo { padding: clamp(11px, 2vw, 24px); }
.school-placeholder { display: grid; place-items: center; color: var(--gold); border: 1px solid #eabf7280; background: #0f2349b0; }
.school-placeholder .icon { width: 55%; height: 55%; }

.hero.compact { padding: clamp(22px, 4vw, 40px); grid-template-columns: auto minmax(0, 1fr) auto; }
.hero.compact h1 { font-size: clamp(1.6rem, 3.6vw, 2.7rem); }
.hero.compact p { margin-top: 6px; }
.hero-badge {
    display: grid; place-items: center;
    width: clamp(56px, 7vw, 76px); aspect-ratio: 1; border-radius: 22px;
    background: linear-gradient(140deg, #f8d998, var(--gold-deep)); color: var(--deep);
    box-shadow: 0 10px 26px #00000033;
}
.hero-badge .icon { width: 55%; height: 55%; }

/* ---------- buttons ---------- */
.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    min-height: 46px; border: 0; border-radius: 12px; padding: 10px 20px;
    background: linear-gradient(125deg, #18315d, #2c58a0);
    color: #fff; font-weight: 700; text-decoration: none; cursor: pointer;
    box-shadow: 0 6px 16px #23498a33;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 10px 22px #23498a45; }
.button:active { transform: translateY(0); }
.button.secondary { background: #fff; color: var(--ink); border: 1px solid #c4d1e6; box-shadow: none; }
.button.secondary:hover { background: var(--blue-soft); }
.button.ghost { background: #ffffff17; border: 1px solid #ffffff38; box-shadow: none; color: #fff; }
.button.ghost:hover { background: #ffffff26; }
.button.small { min-height: 40px; padding: 7px 14px; font-size: .9rem; margin-left: auto; }
.button.danger { background: var(--danger); box-shadow: 0 6px 16px #b3362f33; }
.button.danger:hover { background: #8f2924; }

/* ---------- presentation grid ---------- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
    --accent: #2c58a0;
    --accent-soft: #e8effc;
    position: relative;
    display: flex; flex-direction: column; gap: 14px;
    min-height: 210px;
    padding: clamp(18px, 2.2vw, 26px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    overflow: hidden;
    overflow-wrap: break-word;
    box-shadow: var(--shadow-sm);
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.card::before {
    content: ""; position: absolute; inset: 0 0 auto 0; height: 5px;
    background: var(--accent);
    background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #fff));
}
.grid > :nth-child(6n+2) { --accent: #0f8a7e; --accent-soft: #e2f5f2; }
.grid > :nth-child(6n+3) { --accent: #c26a12; --accent-soft: #fcefdf; }
.grid > :nth-child(6n+4) { --accent: #7a3fb8; --accent-soft: #f1e8fb; }
.grid > :nth-child(6n+5) { --accent: #c23a5b; --accent-soft: #fbe6ec; }
.grid > :nth-child(6n+6) { --accent: #2f7d32; --accent-soft: #e6f3e6; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-no { font-size: 1.6rem; font-weight: 800; line-height: 1; color: var(--accent); opacity: .22; }
.card h2 { font-size: clamp(1.05rem, 1.5vw, 1.25rem); overflow-wrap: break-word; word-break: normal; line-break: strict; }
.logo { width: 60px; height: 60px; border-radius: 16px; object-fit: contain; background: var(--accent-soft, var(--blue-soft)); flex: none; }
.fallback { display: grid; place-items: center; color: var(--accent, var(--blue)); }
.fallback .icon { width: 50%; height: 50%; }
.card-action {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin-top: auto; padding: 10px 10px 10px 16px; border-radius: 14px;
    background: var(--accent-soft); color: var(--accent);
    font-size: .93rem; font-weight: 700;
}
.card-action .go {
    display: grid; place-items: center; flex: none;
    width: 38px; height: 38px; border-radius: 11px;
    background: var(--accent); color: #fff;
    transition: transform .2s ease;
}
.card-action .go .icon { width: 19px; height: 19px; }
a.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, #fff); box-shadow: var(--shadow-md); transform: translateY(-4px); }
a.card:hover .go { transform: translate(2px, -2px) scale(1.06); }
.card.no-link { background: #fbfcfe; }
.card.no-link .card-action { background: #eef1f6; color: var(--muted); font-weight: 600; }
.card.no-link .go { background: #c9d2e0; }

/* ---------- empty state ---------- */
.empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 50px 20px; border: 2px dashed #c8d5ea; border-radius: var(--radius); background: #fff; }
.empty-icon { display: grid; place-items: center; width: 76px; height: 76px; border-radius: 22px; background: var(--blue-soft); color: var(--blue); }
.empty-icon .icon { width: 40px; height: 40px; }
.empty .button { margin-top: 8px; }

/* ---------- manage ---------- */
.workspace { display: grid; gap: 20px; grid-template-columns: minmax(0, 4fr) minmax(0, 5fr); align-items: start; }
.settings { display: grid; gap: 20px; }
.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    padding: clamp(18px, 2.4vw, 28px);
    box-shadow: var(--shadow-sm);
}
.panel.is-editing { border-color: var(--gold-deep); box-shadow: 0 0 0 3px #f5ca7955, var(--shadow-sm); }
.panel-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.panel-heading p { font-size: .88rem; }
.panel-icon { display: grid; place-items: center; flex: none; width: 48px; height: 48px; border-radius: 14px; background: var(--blue-soft); color: var(--blue); }
.panel-icon .icon { width: 24px; height: 24px; }
.is-editing .panel-icon { background: #fcefd6; color: #9a6410; }
.school-panel .school-logo { width: 56px; padding: 6px; border-radius: 14px; box-shadow: 0 0 0 1px var(--border); }
.school-panel .school-placeholder { background: var(--deep); }

label { display: flex; align-items: center; gap: 8px; margin: 16px 0 6px; font-weight: 700; }
label .icon { color: var(--blue); width: 19px; height: 19px; }
label small { font-weight: 400; }
input, button { font: inherit; }
input:not([type="checkbox"]) {
    width: 100%; min-width: 0; min-height: 48px;
    border: 1.5px solid #c4d1e6; border-radius: 12px; padding: 10px 14px;
    background: #fbfcfe; color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:not([type="checkbox"]):hover { border-color: #93a9cf; }
input:not([type="checkbox"]):focus { outline: none; border-color: var(--blue); background: #fff; box-shadow: 0 0 0 4px #2c58a026; }
input[type="file"] { padding: 8px; cursor: pointer; border-style: dashed; }
input[type="file"]::file-selector-button {
    margin-right: 12px; border: 0; border-radius: 9px; padding: 7px 14px;
    background: var(--blue-soft); color: var(--navy); font-weight: 700; cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: #d6e2f7; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--danger); }
small, .muted { color: var(--muted); font-weight: 400; }
.hint { display: block; margin-top: 6px; font-size: .84rem; }
.actions, .remove-logo { display: flex; align-items: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.remove-logo { padding: 10px; border-radius: 12px; background: #f6f8fc; }
.remove-logo label { margin: 0; font-weight: 600; }
.remove-logo .logo { width: 44px; height: 44px; }

.delete { margin-top: 20px; border-top: 1px dashed var(--border); padding-top: 14px; }
.delete summary {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    min-height: 40px; padding: 6px 12px; border-radius: 10px;
    color: var(--danger); font-weight: 600; list-style: none;
}
.delete summary::-webkit-details-marker { display: none; }
.delete summary:hover { background: #fcebea; }
.delete form { margin-top: 10px; padding: 14px; border-radius: 12px; background: #fdf1f0; border: 1px solid #f3cfcc; }
.delete form p { margin-bottom: 10px; color: #842822; font-size: .9rem; }

.notice { display: flex; align-items: center; gap: 10px; margin: 0 0 18px; padding: 13px 18px; border-radius: 14px; background: #e4f4ec; color: var(--ok); border: 1px solid #bfe3cf; font-weight: 600; }
.notice.error { background: #fbe9e7; color: #842822; border-color: #f1c6c1; }

.count { display: inline-grid; place-items: center; min-width: 30px; height: 26px; margin-left: 6px; padding: 0 8px; border-radius: 99px; background: var(--blue); color: #fff; font-size: .82rem; font-weight: 700; vertical-align: 2px; }
.empty-list { display: flex; align-items: center; gap: 10px; padding: 24px 4px; color: var(--muted); }
.plan-list { margin: 0; padding: 0; list-style: none; }
.plan-list li {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
    margin-top: 8px; padding: 10px 12px;
    border: 1px solid transparent; border-radius: 14px;
    overflow-wrap: anywhere;
    transition: background .15s ease;
}
.plan-list li:nth-child(odd) { background: #f7f9fd; }
.plan-list li:hover { background: #eef3fc; }
.plan-list li.current { background: #fff7e6; border-color: #f0d49a; }
.plan-no { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 9px; background: #fff; border: 1px solid var(--border); color: var(--muted); font-size: .82rem; font-weight: 700; }
.plan-list .logo { width: 42px; height: 42px; border-radius: 11px; background: var(--blue-soft); }
.plan-name { flex: 1 1 140px; font-weight: 600; }
.plan-controls, .plan-controls form { display: flex; gap: 6px; align-items: center; }
.plan-controls { margin-left: auto; }
.icon-btn {
    display: grid; place-items: center;
    width: 44px; height: 44px; padding: 0;
    border: 1px solid #c9d6ea; border-radius: 11px;
    background: #fff; color: var(--blue); cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}
.icon-btn .icon { width: 22px; height: 22px; }
.icon-btn:hover:not(:disabled) { background: var(--blue-soft); border-color: var(--blue); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.edit-btn {
    display: inline-flex; align-items: center; gap: 7px;
    min-height: 44px; padding: 8px 14px; border-radius: 11px;
    background: var(--blue); color: #fff; font-weight: 700; font-size: .92rem; text-decoration: none;
}
.edit-btn:hover { background: var(--navy); }
.edit-btn .icon { width: 18px; height: 18px; }

/* ---------- footer ---------- */
.site-footer { padding: 22px 0; text-align: center; background: var(--deep); color: #c9d7f0; border-top: 3px solid var(--gold-deep); font-size: .92rem; }

/* ---------- tablet ---------- */
@media (max-width: 1100px) {
    .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .wrap { width: calc(100% - 40px); }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
    .workspace { grid-template-columns: minmax(0, 1fr); }
    .hero.compact { grid-template-columns: auto minmax(0, 1fr); }
    .hero.compact .button.ghost { grid-column: 1 / -1; justify-self: start; }
}

/* ---------- mobile: bottom tab bar ---------- */
@media (max-width: 640px) {
    .wrap { width: calc(100% - 28px); }
    .bar { min-height: 60px; padding-block: 8px; }
    .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
    .brand-mark .icon { width: 22px; height: 22px; }
    .main-nav {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
        justify-content: space-around; gap: 0;
        padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
        border-radius: 0; border: 0; border-top: 1px solid #ffffff1f;
        background: #08152ef7;
        box-shadow: 0 -6px 20px #08152e40;
    }
    .main-nav a { flex: 1; flex-direction: column; gap: 2px; min-height: 56px; padding: 6px; font-size: .8rem; justify-content: center; }
    .main-nav .icon { width: 24px; height: 24px; }
    body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
    main { padding-top: 16px; }
    .presentation-hero { grid-template-columns: 1fr; text-align: center; justify-items: center; }
    .presentation-hero .school-logo { grid-row: 1; width: 96px; }
    .hero-chips { justify-content: center; }
    .hero { border-radius: 22px; margin-bottom: 18px; padding: 26px 18px; }
    .hero.compact .button.ghost { justify-self: stretch; }
    .grid { gap: 12px; }
    .card { min-height: 180px; gap: 10px; padding: 14px; border-radius: 16px; }
    .card-no { font-size: 1.25rem; }
    .logo { width: 48px; height: 48px; border-radius: 13px; }
    .card-action { padding: 7px 7px 7px 11px; font-size: .82rem; border-radius: 12px; }
    .card-action .go { width: 32px; height: 32px; border-radius: 9px; }
    .actions .button { flex: 1 1 auto; }
    .plan-list li { padding: 10px; }
    .plan-controls { width: 100%; justify-content: flex-end; }
    .button.small span { display: none; }
    .button.small { padding: 7px 10px; }
}
@media (max-width: 380px) {
    .grid { grid-template-columns: minmax(0, 1fr); }
    .card { min-height: 0; }
    .brand-text small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before { transition: none !important; scroll-behavior: auto !important; }
    a.card:hover, .button:hover { transform: none; }
}
