:root{
  --bg:#f3f6fb;
  --card:#ffffff;
  --line:#dbe4f0;
  --text:#172554;
  --muted:#64748b;
  --accent:#2563eb;
}
*{box-sizing:border-box}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
}
.page{padding:18px}
.topbar{margin-bottom:14px}
.topbar h1{margin:0 0 4px;font-size:28px}
.topbar p{margin:0;color:var(--muted)}
.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:16px;
  box-shadow:0 6px 18px rgba(15,23,42,.05);
}
.filters{padding:16px;margin-bottom:14px}
.grid{
  display:grid;
  grid-template-columns:repeat(4,minmax(140px,1fr)) auto auto;
  gap:12px;
  align-items:end;
}
.filter-layout{
  display:grid;
  grid-template-columns:minmax(0,1fr) max-content max-content;
  gap:12px;
  align-items:end;
}
.filter-selects{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:12px;
}
.filter-selects select{width:100%}
.multi-select{position:relative}
.multi-select-toggle{
  width:100%;
  min-height:42px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  text-align:left;
  font-weight:400;
}
.multi-select-arrow{font-size:12px;color:var(--muted)}
.multi-select.open .multi-select-arrow{transform:rotate(180deg)}
.multi-select-menu{
  display:none;
  position:absolute;
  z-index:20;
  top:calc(100% + 6px);
  left:0;
  right:0;
  max-height:240px;
  overflow:auto;
  padding:6px;
  border:1px solid var(--line);
  border-radius:10px;
  background:#fff;
  box-shadow:0 12px 30px rgba(15,23,42,.12);
}
.multi-select.open .multi-select-menu{display:block}
.multi-option{
  display:flex;
  align-items:center;
  gap:8px;
  padding:8px 6px;
  border-radius:8px;
  font-size:14px;
  color:var(--text);
}
.multi-option:hover{background:#eff6ff}
.multi-option input{margin:0}
.filter-checks,.filter-actions{
  display:flex;
  flex-direction:column;
  gap:8px;
}
.filter-actions button,.filter-actions .secondary{
  width:100%;
  text-align:center;
  white-space:nowrap;
}
label span{display:block;margin-bottom:6px;font-size:13px;color:var(--muted)}
select, textarea, button, .secondary{
  border:1px solid var(--line);
  border-radius:10px;
  background:#fff;
  padding:10px 12px;
  font-size:14px;
}
.check{display:flex;gap:8px;align-items:center;min-height:42px;white-space:nowrap}
.actions{display:flex;gap:10px}
button,.secondary{
  cursor:pointer;
  text-decoration:none;
  color:var(--text);
}
button:hover,.secondary:hover,.mode-tabs a:hover,.record:hover{border-color:#93c5fd}
.layout{
  display:grid;
  grid-template-columns:260px 1fr 220px;
  gap:14px;
  min-height:calc(100vh - 180px);
  height:calc(100vh - 180px);
}
.left,.right,.viewer,.viewer-toolbar{padding:14px}
.left{display:flex;flex-direction:column;min-height:0}
.left-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px}
.left-head-main{display:flex;align-items:center;gap:8px}
.left-head h2,.right h2{margin:0;font-size:18px}
.small-btn{padding:6px 10px;font-size:12px;border-radius:8px}
.record-list{overflow-y:auto;display:flex;flex-direction:column;gap:10px;padding-right:4px;flex:1;min-height:0}
.record{
  display:block;
  text-decoration:none;
  color:inherit;
  border:1px solid var(--line);
  border-radius:12px;
  padding:12px;
}
.record.active{border-color:var(--accent);background:#eff6ff}
.record-title{font-weight:700;margin-bottom:6px}
.record-meta{font-size:13px;color:var(--muted);margin-bottom:8px}
.record-flags{display:flex;flex-wrap:wrap;gap:6px}
.tag{
  display:inline-flex;
  padding:4px 8px;
  border-radius:999px;
  background:#eef2ff;
  color:#3730a3;
  font-size:12px;
}
.tag.done{background:#ecfdf5;color:#166534}
.tag.fav{background:#fff7ed;color:#c2410c}
.center{display:flex;flex-direction:column;gap:14px;min-width:0}
.viewer-toolbar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
}
.mode-tabs{display:flex;gap:8px;flex-wrap:wrap}
.mode-tabs a{
  text-decoration:none;
  border:1px solid var(--line);
  padding:10px 14px;
  border-radius:10px;
  color:var(--text);
}
.mode-tabs a.active{
  background:#eff6ff;
  border-color:var(--accent);
  color:#1d4ed8;
}
.state-buttons{display:flex;gap:8px}
.viewer{display:flex;flex-direction:column;gap:12px;min-height:0;height:100%}
.info .title{font-size:20px;font-weight:800;margin-bottom:6px}
.info .meta{font-size:14px;color:var(--muted)}
.pdf-inline-toolbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.pdf-toolbar-right{justify-content:flex-end}
.pdf-panel{display:flex;flex-direction:column;gap:8px;min-height:0;width:100%}
.pdf-section-head{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-bottom:8px}
.pdf-frame{
  width:100%;
  height:auto;
  flex:1;
  min-height:0;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  overflow:hidden;
}
.note-form{display:flex;flex-direction:column;gap:10px}
.note-form textarea{
  width:100%;
  min-height:180px;
  resize:vertical;
}
.empty{color:var(--muted);padding:20px 6px}
.empty.big{font-size:18px;text-align:center;padding:80px 20px}

@media (max-width: 1200px){
  .layout{grid-template-columns:320px 1fr}
  .right{grid-column:1 / -1}
}
@media (max-width: 900px){
  .grid{grid-template-columns:repeat(2, minmax(140px,1fr))}
  .filter-layout{grid-template-columns:1fr}
  .filter-selects{grid-template-columns:repeat(2, minmax(140px,1fr))}
  .filter-checks,.filter-actions{flex-direction:row;flex-wrap:wrap}
  .layout{grid-template-columns:1fr}
}

.topbar{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:12px;
}
.user-bar{
  display:flex;
  align-items:center;
  gap:10px;
  color:var(--muted);
}
.user-bar form{margin:0}

.auth-page{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
}
.auth-card{
  width:100%;
  max-width:420px;
  padding:20px;
}
.auth-card h1{margin-top:0}
.auth-form{display:flex;flex-direction:column;gap:12px}
.auth-form input{
  width:100%;
  border:1px solid var(--line);
  border-radius:10px;
  padding:10px 12px;
  font-size:14px;
}
.flash{
  margin:10px 0;
  padding:10px;
  border-radius:10px;
  background:#fff7ed;
  color:#9a3412;
  border:1px solid #fed7aa;
}
.auth-link{margin-top:12px;color:var(--muted)}

.lang-switch{display:flex;gap:6px}
.lang-switch .secondary.active{background:#dbeafe;border-color:#60a5fa;color:#1d4ed8}

.portal-body{
  background:var(--bg);
  color:var(--text);
}
.portal-page{padding:20px;max-width:1200px;margin:0 auto}
.portal-header,.portal-footer{background:var(--card);border-color:var(--line)}
.portal-header{display:flex;justify-content:space-between;gap:16px;padding:20px;margin-bottom:14px}
.neon-label{color:var(--accent);font-size:12px;letter-spacing:.08em;margin:0 0 8px;font-weight:600}
.portal-header h1{margin:0 0 8px;font-size:32px;color:var(--text)}
.portal-subtitle{margin:0;color:var(--muted)}
.portal-actions{display:flex;flex-direction:column;align-items:flex-end;gap:10px;color:var(--muted)}
.user-inline{display:flex;align-items:center;gap:10px}
.user-inline form{margin:0}
.feature-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;margin-bottom:14px}
.feature-grid-portal{grid-template-columns:repeat(3,1fr)}
.feature-tile{
  display:block;
  padding:18px;
  border-radius:16px;
  border:1px solid var(--line);
  background:#fff;
  color:var(--text);
  text-decoration:none;
  min-height:200px;
  transition:all .2s ease;
}
.feature-tile:hover{transform:translateY(-2px);border-color:#93c5fd;box-shadow:0 10px 18px rgba(15,23,42,.08)}
.feature-tile.disabled{opacity:.95}
.tile-icon{font-size:34px;margin-bottom:12px}
.feature-tile h2{margin:0 0 10px;color:var(--text)}
.feature-tile p{margin:0;color:var(--muted);line-height:1.5}
.learn-subpage{padding:16px;display:flex;flex-direction:column;min-height:calc(100vh - 180px)}
.learn-sub-layout{display:grid;grid-template-columns:280px 1fr;gap:14px;flex:1;min-height:0}
.learn-sidebar h2{margin-top:0}
.learn-sidebar{overflow:auto;min-height:0}
.learn-sub-layout > div{min-height:0;display:flex}
.learn-sub-layout .pdf-panel{height:100%}
.learn-sub-layout .pdf-frame{height:100%}
.chapter-tabs{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:12px}
.placeholder-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:14px;margin-top:12px}
.article-list{display:grid;grid-template-columns:repeat(2,1fr);gap:14px;margin-top:12px}
.article-card{border:1px solid var(--line);border-radius:14px;padding:14px;background:#fff}
.article-card h3{margin:0 0 8px}
.content-image{width:100%;max-height:260px;object-fit:cover;border-radius:10px;border:1px solid var(--line);margin:6px 0 10px;background:#f8fafc}

.forum-editor{padding:16px;margin-bottom:14px}
.forum-form{display:flex;flex-direction:column;gap:10px}
.forum-form-row{display:grid;grid-template-columns:200px 1fr;gap:10px}
.forum-form input,.forum-form textarea,.reply-form input{
  width:100%;
  border:1px solid var(--line);
  border-radius:10px;
  padding:10px 12px;
  font-size:14px;
}
.forum-form textarea{min-height:120px;resize:vertical}
.forum-list{display:flex;flex-direction:column;gap:12px}
.forum-post{padding:16px}
.forum-post-head{display:flex;justify-content:space-between;gap:10px}
.forum-post h3{margin:8px 0 0}
.reply-list{display:flex;flex-direction:column;gap:8px;margin:12px 0}
.message-scroll{max-height:208px;overflow-y:auto;padding-right:4px;margin-bottom:0}
.chat-message-section{padding:16px;margin-bottom:14px}
.chat-message-section h2{margin:0 0 8px}
.chat-message-section:last-child{margin-bottom:0}
.reply-item{padding:8px 10px;border:1px solid var(--line);border-radius:10px;background:#f8fafc;min-height:64px}
.announcement-item{width:100%;text-align:left;display:block}
.reply-item .record-meta{margin-left:8px}
.reply-form{display:flex;gap:8px}
.portal-footer{display:flex;justify-content:space-between;gap:16px;padding:18px}
.logo-box{display:flex;gap:14px;align-items:center}
.logo-mark{
  width:64px;height:64px;border-radius:14px;
  border:1px solid var(--line);display:grid;place-items:center;
  background:#eff6ff;font-weight:700;color:#1d4ed8;
}
.logo-mark-img{
  width:100px;
  height:100px;
  border-radius:14px;
  object-fit:cover;
  border:1px solid var(--line);
  background:#fff;
}
.logo-box p,.contact-box p{margin:4px 0 0;color:var(--muted)}
.contact-box h3{margin:0;color:var(--text)}

@media (max-width: 960px){
  .feature-grid{grid-template-columns:repeat(2,1fr)}
  .portal-header,.portal-footer{flex-direction:column;align-items:flex-start}
  .portal-actions{align-items:flex-start}
  .learn-sub-layout,.placeholder-grid,.article-list{grid-template-columns:1fr}
  .forum-form-row{grid-template-columns:1fr}
}
@media (max-width: 620px){
  .feature-grid{grid-template-columns:1fr}
}

.game-grid{grid-template-columns:repeat(3,1fr)}
.game-grid-wide{grid-template-columns:repeat(3,1fr)}
.game-layout{display:grid;grid-template-columns:1fr 320px;gap:16px}
.game-main{padding:16px}
.game-toolbar{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;padding:8px 10px;background:#f8fafc;border:1px solid var(--line);border-radius:10px}
.game-hint{color:var(--muted);margin:6px 0 10px;font-size:13px}
.leaderboard-panel{padding:16px}
.leaderboard-panel h2{margin:0 0 12px;color:var(--text)}
.leaderboard-panel ol{margin:0;padding-left:20px;display:flex;flex-direction:column;gap:8px}
.leaderboard-panel li{display:flex;justify-content:space-between;gap:10px;color:var(--text)}

.board-2048{display:grid;grid-template-columns:repeat(4,90px);gap:8px;padding:12px;background:#f1f5f9;border-radius:12px;width:max-content;border:1px solid var(--line)}
.cell-2048{width:90px;height:90px;display:grid;place-items:center;font-weight:700;font-size:26px;background:#e2e8f0;border-radius:10px;color:#334155}
.cell-2048[data-value="0"]{background:#e2e8f0;color:transparent}
.cell-2048[data-value="2"]{background:#dbeafe;color:#1e3a8a}
.cell-2048[data-value="4"]{background:#bfdbfe;color:#1e3a8a}
.cell-2048[data-value="8"]{background:#fde68a;color:#78350f}
.cell-2048[data-value="16"]{background:#fdba74;color:#7c2d12}
.cell-2048[data-value="32"]{background:#fb923c;color:#7c2d12}
.cell-2048[data-value="64"]{background:#f87171;color:#7f1d1d}
.cell-2048[data-value="128"],
.cell-2048[data-value="256"],
.cell-2048[data-value="512"],
.cell-2048[data-value="1024"],
.cell-2048[data-value="2048"]{background:#c4b5fd;color:#4c1d95}

.sudoku-panel{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px}
.board-sudoku{display:grid;grid-template-columns:repeat(9,42px);gap:4px}
.sudoku-cell{width:42px;height:42px;text-align:center;font-size:18px;border:1px solid var(--line);background:#fff;color:var(--text);border-radius:6px}
.sudoku-cell.given{background:#f1f5f9;font-weight:700}
.sudoku-cell.wrong{border-color:#ef4444;background:#fee2e2}
.sudoku-cell.v-heavy-left{border-left:3px solid #334155}
.sudoku-cell.v-heavy-right{border-right:3px solid #334155}
.sudoku-cell.h-heavy-top{border-top:3px solid #334155}
.sudoku-cell.h-heavy-bottom{border-bottom:3px solid #334155}

#tetrisCanvas{background:#f8fafc;border:1px solid var(--line);border-radius:8px}

@media (max-width: 980px){
  .game-layout{grid-template-columns:1fr}
  .game-grid{grid-template-columns:1fr}
}


#gameHost{min-height:420px}


.code-lab{padding:16px;display:flex;flex-direction:column;gap:10px}
.iframe-lab{min-height:calc(100vh - 180px)}
.iframe-tabs{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.iframe-tabs button{width:100%;font-weight:700}
.iframe-tabs button.active{background:#eff6ff;border-color:var(--accent);color:#1d4ed8}
.iframe-stack{position:relative;flex:1;min-height:70vh;border:1px solid var(--line);border-radius:12px;background:#fff;overflow:hidden}
.tool-frame{position:absolute;inset:0;width:100%;height:100%;border:0;background:#fff;display:none}
.tool-frame.active{display:block}
.editor-row{display:grid;grid-template-columns:2fr 1fr;gap:12px;align-items:start}
.editor-panel{display:flex;flex-direction:column;gap:6px;min-width:0}
.code-lab textarea{width:100%;font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
#codeInput{min-height:220px}
#codeInputs{min-height:220px}
.code-lab pre{min-height:120px;background:#0b1220;color:#dbeafe;padding:12px;border-radius:10px;overflow:auto}

@media (max-width: 900px){
  .editor-row{grid-template-columns:1fr}
}


.nono-board-wrap{display:grid;grid-template-columns:80px auto;grid-template-rows:80px auto;gap:4px;align-items:start}
.nono-corner{border:1px solid var(--line);border-radius:8px;background:#f8fafc}
.nono-top{display:grid;gap:2px}
.nono-left{display:grid;gap:2px}
.nono-grid{display:grid;gap:2px;width:max-content}
.nono-clue-top,.nono-clue-left{border:1px solid var(--line);background:#f8fafc;border-radius:6px;font-size:11px;color:var(--muted);display:flex;align-items:center;justify-content:center;line-height:1.1;text-align:center;padding:2px}
.nono-cell{width:32px;height:32px;padding:0;border:1px solid #cbd5e1;background:#fff}
.nono-cell.on{background:#1e3a8a}



.mine-board{display:grid;gap:1px;background:#cbd5e1;padding:8px;border-radius:12px;width:max-content;max-width:100%;overflow:auto;border:1px solid #e2e8f0}
.mine-cell{width:24px;height:24px;padding:0;border:1px solid #93c5fd;background:#bfdbfe;font-size:12px;border-radius:4px;color:#1e3a8a;box-shadow:inset 0 -2px 0 rgba(37,99,235,.18)}
.mine-cell:hover{background:#dbeafe}
.mine-cell.open{background:#f8fafc;border-color:#cbd5e1;color:#334155;font-weight:600;box-shadow:inset 0 0 0 1px rgba(148,163,184,.22)}

.hanoi-board{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;min-height:320px}
.hanoi-rod{display:flex;flex-direction:column-reverse;align-items:center;gap:6px;border:1px solid var(--line);border-radius:10px;padding:10px;background:#f8fafc;cursor:pointer}
.hanoi-rod.selected{outline:2px solid #60a5fa}
.hanoi-disk{height:24px;border-radius:999px;background:#bfdbfe;border:1px solid #60a5fa;display:flex;align-items:center;justify-content:center;font-size:12px}


.blessing-top{padding:20px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;margin-bottom:14px;text-align:center}
.blessing-top img{width:400px;height:400px;object-fit:cover;border-radius:14px;border:1px solid var(--line);background:#fff}
.blessing-btn{font:inherit;text-align:left}
.blessing-modal{position:fixed;inset:0;background:rgba(15,23,42,.45);display:grid;place-items:center;z-index:60}
.blessing-modal[hidden]{display:none !important}
.blessing-modal-card{width:min(92vw,460px);background:#fff;border-radius:14px;padding:16px;border:1px solid var(--line)}
.donation-qr{width:260px;max-width:100%;display:block;margin:0 auto}
