/* Two visual themes: "minecraft" (pixel blocks) and "roblox" (smooth, rounded). */
:root, :root[data-theme="minecraft"] {
  --font: "Courier New", "Lucida Console", monospace;
  --bg: #3b2a1e;
  --bg-pattern: repeating-conic-gradient(#4a3424 0 25%, #3b2a1e 0 50%) 0 0 / 16px 16px;
  --bar: #5b8c32;
  --bar-edge: #3e6a1f;
  --bar-text: #fff;
  --card: #8b8b8b;
  --card-text: #fff;
  --card-shadow: inset -4px -4px 0 #555, inset 4px 4px 0 #b8b8b8;
  --border: 3px solid #1b1b1b;
  --radius: 0;
  --text-shadow: 2px 2px 0 #3a3a3a;
  --accent: #5b8c32;
  --accent-text: #fff;
  --btn: #7a7a7a;
  --btn-shadow: inset -3px -3px 0 #4a4a4a, inset 3px 3px 0 #b0b0b0;
  --chat-bg: rgba(0, 0, 0, .62);
  --chat-text: #fff;
  --me-bg: rgba(91, 140, 50, .55);
  --input-bg: #000;
  --input-text: #fff;
  --muted: #d8d8d8;
  --s-unknown: #9d9d97; --s-gap: #b02e26; --s-progress: #e0b52a; --s-mastered: #5e7c16;
  --heading-transform: uppercase;
  --weight: 700;
}
:root[data-theme="clean"] {
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --bg: #eef1f4;
  --bg-pattern: none;
  --bar: #232527;
  --bar-edge: #232527;
  --bar-text: #fff;
  --card: #fff;
  --card-text: #1d1f21;
  --card-shadow: 0 2px 10px rgba(20, 30, 40, .08);
  --border: 1px solid #dde2e7;
  --radius: 16px;
  --text-shadow: none;
  --accent: #00a2ff;
  --accent-text: #fff;
  --btn: #f2f4f6;
  --btn-shadow: none;
  --chat-bg: #f7f9fb;
  --chat-text: #1d1f21;
  --me-bg: #dff1ff;
  --input-bg: #fff;
  --input-text: #1d1f21;
  --muted: #5c6670;
  --s-unknown: #c4cbd2; --s-gap: #ff4d4f; --s-progress: #ffb020; --s-mastered: #00b06b;
  --heading-transform: none;
  --weight: 700;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg-pattern), var(--bg);
  color: var(--card-text);
  min-height: 100vh;
  font-size: 16px;
}
h1, h2, h3 { text-transform: var(--heading-transform); font-weight: var(--weight); margin: 0 0 .5em; }
[hidden] { display: none !important; }

.bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--bar); color: var(--bar-text);
  border-bottom: 6px solid var(--bar-edge);
}
:root[data-theme="minecraft"] .bar { border-bottom: 10px solid #866043; box-shadow: 0 4px 0 #5d4330; }
.bar .name { font-weight: 700; font-size: 18px; text-shadow: var(--text-shadow); }
.bar .stat { opacity: .95; font-size: 14px; }
.bar .spacer { flex: 1; }

.avatar { width: 40px; height: 40px; flex: none; position: relative; background: #f3e27a; border: 3px solid #1b1b1b; }
.avatar::before, .avatar::after { content: ""; position: absolute; top: 12px; width: 6px; height: 6px; background: #1b1b1b; }
.avatar::before { left: 8px; } .avatar::after { right: 8px; }
.avatar i { position: absolute; left: 10px; right: 10px; bottom: 7px; height: 4px; background: #1b1b1b; }
:root[data-theme="clean"] .avatar { border-radius: 10px; border-width: 2px; }

.toggle { display: inline-flex; border: var(--border); border-radius: var(--radius); overflow: hidden; }
.toggle button { border: 0; border-radius: 0; box-shadow: none; padding: 6px 12px; background: transparent; color: var(--bar-text); }
.toggle button.on { background: rgba(255, 255, 255, .25); }
:root[data-theme="clean"] .toggle { border-color: #444; }

button, .btn {
  font: inherit; font-weight: 700; cursor: pointer;
  background: var(--btn); color: var(--card-text);
  border: var(--border); border-radius: var(--radius); box-shadow: var(--btn-shadow);
  padding: 9px 16px; text-shadow: var(--text-shadow);
}
:root[data-theme="clean"] button, :root[data-theme="clean"] .btn { border-radius: 999px; }
button.primary { background: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid #ffd54a; outline-offset: 2px; }

main { max-width: 1040px; margin: 0 auto; padding: 18px 16px 60px; }

.card {
  background: var(--card); color: var(--card-text);
  border: var(--border); border-radius: var(--radius); box-shadow: var(--card-shadow);
  padding: 16px; margin-bottom: 16px; text-shadow: var(--text-shadow);
}
.card .sub { color: var(--muted); font-size: 14px; margin-top: -4px; margin-bottom: 12px; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 14px; }
.dot { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-right: 6px; border: 2px solid #1b1b1b; }
:root[data-theme="clean"] .dot { border-radius: 50%; border: 0; }
.s-unknown { background: var(--s-unknown); } .s-gap { background: var(--s-gap); }
.s-progress { background: var(--s-progress); } .s-mastered { background: var(--s-mastered); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.tile {
  text-align: left; display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; min-height: 64px; font-weight: 600; font-size: 15px; line-height: 1.25;
}
.tile .dot { flex: none; margin-top: 2px; width: 18px; height: 18px; }
.tile small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 4px; }

.topic-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 10px; border: var(--border); border-radius: var(--radius); background: rgba(0, 0, 0, .12); }
:root[data-theme="clean"] .chip { border-radius: 999px; background: #f2f4f6; }

.hook { border-left: 6px solid var(--accent); padding: 8px 12px; margin: 10px 0; background: rgba(0, 0, 0, .12); }
:root[data-theme="clean"] .hook { background: #f2f9ff; border-radius: 10px; }
details summary { cursor: pointer; font-weight: 700; margin-top: 8px; }

.chat {
  background: var(--chat-bg); color: var(--chat-text);
  border: var(--border); border-radius: var(--radius);
  padding: 12px; height: min(52vh, 520px); overflow-y: auto; margin-bottom: 10px;
}
.msg { white-space: pre-wrap; overflow-wrap: anywhere;padding: 8px 12px; margin: 0 0 8px; max-width: 88%; line-height: 1.4; text-shadow: none; }
.msg.tutor { background: rgba(255, 255, 255, .08); }
:root[data-theme="clean"] .msg.tutor { background: #fff; border: 1px solid #e3e8ed; border-radius: 14px 14px 14px 4px; }
.msg.me { background: var(--me-bg); margin-left: auto; }
:root[data-theme="clean"] .msg.me { border-radius: 14px 14px 4px 14px; }
.msg .who { display: block; font-size: 12px; opacity: .7; margin-bottom: 2px; }
:root[data-theme="minecraft"] .msg.tutor .who { color: #ffd54a; opacity: 1; }
.thinking { opacity: .7; font-style: italic; }

.composer { display: flex; gap: 8px; }
textarea, input[type="text"], input[type="password"], select {
  font: inherit; background: var(--input-bg); color: var(--input-text);
  border: var(--border); border-radius: var(--radius); padding: 10px 12px; width: 100%;
}
:root[data-theme="clean"] textarea, :root[data-theme="clean"] input, :root[data-theme="clean"] select { border-radius: 12px; }
textarea { resize: vertical; min-height: 48px; max-height: 200px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.quiz-q { margin-bottom: 14px; }
.quiz-q label { display: block; margin-bottom: 6px; font-weight: 600; }
.ok { color: #7bd34a; } .bad { color: #ff6b5e; }
:root[data-theme="clean"] .ok { color: #00965a; } :root[data-theme="clean"] .bad { color: #e0302e; }
.result-big { font-size: 22px; font-weight: 700; margin: 6px 0 10px; }

.login-wrap { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.error { color: #ff6b5e; min-height: 1.2em; margin-top: 8px; }
.warn { background: #fff3cd; color: #5c4400; padding: 10px 12px; border-radius: 8px; text-shadow: none; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: var(--border); border-radius: var(--radius); cursor: pointer; font-weight: 600; background: rgba(0, 0, 0, .12); }
:root[data-theme="clean"] .choice { border-radius: 999px; background: #f2f4f6; }
.suggest { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.suggest h2 { margin: 0; }

/* parent page */
.scroll { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; text-shadow: none; }
table.list th, table.list td { text-align: left; padding: 7px 8px; border-bottom: 1px solid rgba(0, 0, 0, .12); vertical-align: top; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi b { display: block; font-size: 26px; }
pre.report { white-space: pre-wrap; font-family: inherit; background: rgba(0, 0, 0, .05); padding: 12px; border-radius: 8px; text-shadow: none; }
.topic-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 4px 0; }
.topic-row select { width: auto; padding: 4px 8px; font-size: 13px; }

@media (max-width: 600px) {
  .bar { gap: 8px; }
  .composer { flex-direction: column; }
  .msg { max-width: 100%; }
}

/* parent page on phones: tables become stacked cards */
@media (max-width: 600px) {
  table.list thead { display: none; }
  table.list tr { display: block; padding: 8px 0; border-bottom: 1px solid rgba(0, 0, 0, .12); }
  table.list td { display: block; border: 0; padding: 2px 0; }
  .kpi b { font-size: 22px; }
  .topic-row { font-size: 15px; }
}

/* drawing board */
.board { padding: 12px; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
.tool { padding: 6px 10px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.tool.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.tool .sw { width: 18px; height: 18px; display: inline-block; border: 2px solid #fff; box-shadow: 0 0 0 1px #1b1b1b; }
:root[data-theme="clean"] .tool .sw { border-radius: 50%; }
#pad { display: block; width: 100%; height: auto; aspect-ratio: 1400 / 720; max-width: calc(60vh * 1400 / 720); margin: 0 auto; background: #fff; touch-action: none; cursor: crosshair;
  border: var(--border); border-radius: var(--radius); }
.board-foot { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 8px; }
.board-foot .sub { margin: 0; }
.msg img.drawing { display: block; max-width: 100%; width: 420px; margin-top: 6px; background: #fff; border: 1px solid rgba(0,0,0,.2); cursor: zoom-in; }
.msg img.drawing.big { width: 100%; cursor: zoom-out; }
.board { user-select: none; -webkit-user-select: none; }
#topic-view.drawing .chat { height: min(30vh, 300px); }

/* homework entry */
.homework { border-left: 8px solid var(--accent); }
.hw-list { display: flex; flex-wrap: wrap; gap: 8px; }
.hw-list button { font-size: 15px; }
.bar select { width: auto; padding: 6px 10px; }

/* ===== Roblox (in-game look): concrete, diamond-plate metal, bright plastic parts, classic avatar, dark HUD chat ===== */
:root[data-theme="roblox"] {
  --font: "Segoe UI", "Arial Rounded MT Bold", Arial, sans-serif;
  --bg: #9a9da1;
  --bg-pattern:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.07) 0 1px, transparent 2px) 0 0 / 7px 7px,
    radial-gradient(circle at 70% 80%, rgba(0,0,0,.08) 0 1px, transparent 2px) 0 0 / 11px 11px,
    linear-gradient(180deg, #b7babd 0%, #8e9195 100%);
  --bar: #c4c7ca;
  --bar-edge: #6d7074;
  --bar-text: #1b1d1f;
  --card: #e9ebec;
  --card-text: #1b1d1f;
  --card-shadow: 0 6px 0 #7d8084, 0 8px 14px rgba(0,0,0,.25), inset 0 2px 0 rgba(255,255,255,.8);
  --border: 2px solid #4b4e52;
  --radius: 6px;
  --text-shadow: none;
  --accent: #e8261c;      /* Roblox red part */
  --accent-text: #fff;
  --btn: #f5cd30;         /* bright yellow part */
  --btn-shadow: inset 0 3px 0 rgba(255,255,255,.45), 0 4px 0 #9c7f0b;
  --chat-bg: rgba(20, 22, 25, .78);   /* in-game chat window */
  --chat-text: #fff;
  --me-bg: rgba(0, 162, 255, .55);
  --input-bg: #1f2124;
  --input-text: #fff;
  --muted: #4c5056;
  --s-unknown: #a3a2a5; --s-gap: #e8261c; --s-progress: #f5cd30; --s-mastered: #4b974b;
  --heading-transform: none;
  --weight: 900;
}
/* top bar: studded diamond-plate metal */
:root[data-theme="roblox"] .bar {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.35) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.18) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, #d6d9db, #9ea2a6);
  border-bottom: 6px solid #5c6064; box-shadow: 0 4px 0 #3f4245;
}
:root[data-theme="roblox"] .bar .name { font-weight: 900; text-shadow: 0 1px 0 rgba(255,255,255,.7); }
/* classic avatar: yellow blocky head with a smile, green torso hint */
:root[data-theme="roblox"] .avatar { background: #f5d84a; border: 2px solid #1b1b1b; border-radius: 8px;
  box-shadow: 0 6px 0 -1px #4b974b, inset -4px -4px 0 rgba(0,0,0,.12); }
:root[data-theme="roblox"] .avatar::before, :root[data-theme="roblox"] .avatar::after { width: 4px; height: 7px; top: 10px; border-radius: 2px; }
:root[data-theme="roblox"] .avatar i { left: 11px; right: 11px; bottom: 9px; height: 8px; background: transparent;
  border: 3px solid #1b1b1b; border-top: 0; border-radius: 0 0 12px 12px; }
:root[data-theme="roblox"] .toggle { border: 2px solid #4b4e52; border-radius: 6px; background: rgba(255,255,255,.35); }
:root[data-theme="roblox"] .toggle button { color: #1b1d1f; text-shadow: none; }
:root[data-theme="roblox"] .toggle button.on { background: #e8261c; color: #fff; }
/* chunky plastic buttons that press down */
:root[data-theme="roblox"] button, :root[data-theme="roblox"] .btn { border-radius: 6px; font-weight: 900; color: #1b1d1f; }
:root[data-theme="roblox"] button.primary { box-shadow: inset 0 3px 0 rgba(255,255,255,.35), 0 4px 0 #8f1610; color: #fff; }
:root[data-theme="roblox"] button:active:not(:disabled) { transform: translateY(3px); box-shadow: inset 0 3px 0 rgba(255,255,255,.3), 0 1px 0 #555; }
:root[data-theme="roblox"] .toggle button, :root[data-theme="roblox"] .toggle button:active { box-shadow: none; transform: none; }
/* cards = concrete slabs; world cards get a coloured plastic stripe like a built part */
:root[data-theme="roblox"] .card {
  background:
    radial-gradient(circle at 30% 40%, rgba(0,0,0,.035) 0 1px, transparent 2px) 0 0 / 6px 6px,
    linear-gradient(180deg, #f1f2f3, #dfe1e3);
}
:root[data-theme="roblox"] #worlds .card { border-top: 10px solid #4b974b; }
:root[data-theme="roblox"] #worlds .card:nth-child(2) { border-top-color: #0d69ac; }
:root[data-theme="roblox"] #worlds .card:nth-child(3) { border-top-color: #e8261c; }
:root[data-theme="roblox"] #worlds .card:nth-child(4) { border-top-color: #f5cd30; }
:root[data-theme="roblox"] .homework { border-left: 10px solid #e8261c; }
:root[data-theme="roblox"] .tile { background: #fff; color: #1b1d1f; box-shadow: 0 4px 0 #8d9094; border: 2px solid #4b4e52; }
:root[data-theme="roblox"] .tile small { color: #5a5e63; }
:root[data-theme="roblox"] .hw-list button, :root[data-theme="roblox"] #quiz-btn { background: #0d69ac; color: #fff; box-shadow: inset 0 3px 0 rgba(255,255,255,.3), 0 4px 0 #063a60; }
:root[data-theme="roblox"] .dot { border: 2px solid #1b1b1b; border-radius: 3px; }
:root[data-theme="roblox"] .chip { background: #fff; border-radius: 6px; }
:root[data-theme="roblox"] .hook { background: #fff6cf; border-left-color: #f5cd30; border-radius: 6px; }
/* chat = Roblox in-game chat window over the world */
:root[data-theme="roblox"] .chat { border: 2px solid #1b1d1f; border-radius: 8px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.08); }
:root[data-theme="roblox"] .msg { border-radius: 6px; font-weight: 600; }
:root[data-theme="roblox"] .msg.tutor { background: rgba(255,255,255,.1); }
:root[data-theme="roblox"] .msg.tutor .who { color: #f5cd30; opacity: 1; font-weight: 900; }
:root[data-theme="roblox"] .msg.me .who { color: #bfe6ff; opacity: 1; font-weight: 900; }
:root[data-theme="roblox"] textarea, :root[data-theme="roblox"] input, :root[data-theme="roblox"] select { border-radius: 6px; }
:root[data-theme="roblox"] .ok { color: #2f8a2f; } :root[data-theme="roblox"] .bad { color: #c41a12; }
:root[data-theme="roblox"] .choice { background: #fff; border-radius: 6px; }
:root[data-theme="roblox"] .tool .sw { border-radius: 3px; }
:root[data-theme="roblox"] .board { background: #2b2d30; color: #fff; }
:root[data-theme="roblox"] .board .sub { color: #d0d3d6; }

/* round-4 fixes: darker red (contrast >= 4.5:1), clear keyboard focus, calmer metal bar, compact bar on phones */
:root[data-theme="roblox"] { --accent: #c81e16; --s-gap: #c81e16; }
:root[data-theme="roblox"] .toggle button.on { background: #c81e16; }
:root[data-theme="roblox"] #worlds .card:nth-child(3) { border-top-color: #c81e16; }
:root[data-theme="roblox"] .homework { border-left-color: #c81e16; }
:root[data-theme="roblox"] :is(button, input, textarea, select, .btn, summary):focus-visible {
  outline: 3px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 6px #111;
}
:root[data-theme="roblox"] .bar {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.2) 0 2px, transparent 2px 10px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.09) 0 2px, transparent 2px 10px),
    linear-gradient(180deg, #d6d9db, #a3a7ab);
}
@media (max-width: 600px) {
  :root[data-theme="roblox"] .bar { padding: 8px 10px; border-bottom-width: 4px; }
  :root[data-theme="roblox"] .toggle button { padding: 5px 8px; }
}
