@font-face {
  font-family: "wubiLexEtymon";
  src: url("fonts/wubi-lex-etymon-v5.otf") format("opentype"),
       url("../assets/fonts/wubi-lex-etymon-v5.otf") format("opentype"),
       url("../data/fonts/wubi-lex-etymon-v5.otf") format("opentype");
  font-display: block;
}

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #0c1220;
  --card: #161e30;
  --text: #e9eeff;
  --muted: rgba(233, 238, 255, 0.55);
  --ok: #3ecf8e;
  --bad: #ff6b7a;
  --now: #ffef3d;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.page {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(8px + var(--safe-top)) 8px calc(8px + var(--safe-bottom));
}
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.bar a {
  color: #8ab4ff;
  text-decoration: none;
  font-weight: 800;
  font-size: 0.9rem;
}
.bar h1 {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  text-align: center;
}
.login-hint {
  margin: 0 0 6px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.login-hint a { color: #8ab4ff; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.toolbar label,
.toolbar button {
  font-size: 0.72rem;
  font-weight: 800;
}
.toolbar select {
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.18);
  background: #1e2840;
  color: #fff;
  padding: 5px 6px;
  font-size: 0.72rem;
}
.toggle {
  appearance: none;
  border: 1px solid rgba(255,255,255,.2);
  background: #24314d;
  color: #fff;
  border-radius: 8px;
  padding: 5px 8px;
  font-weight: 800;
  cursor: pointer;
}
.toggle.is-on {
  background: #3d6fd4;
  border-color: #7ec8ff;
}
.status {
  margin: 0 0 6px;
  font-size: 0.8rem;
  font-weight: 800;
  color: #8ab4ff;
  text-align: center;
}
.board {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}
.cell {
  position: relative;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,.12);
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  cursor: pointer;
  overflow: hidden;
}
.cell.is-now {
  border-color: var(--now);
  box-shadow: 0 0 0 3px rgba(255, 239, 61, 0.35);
  background: #fff8d6;
}
.cell.is-ok { border-color: var(--ok); }
.cell.is-bad { border-color: var(--bad); }
.cell.is-empty {
  visibility: hidden;
  pointer-events: none;
}
.cell__glyph {
  font-family: "wubiLexEtymon", "Microsoft YaHei", sans-serif;
  font-size: clamp(1.4rem, 7vw, 2.1rem);
  font-weight: 800;
  line-height: 1;
}
.cell__mem {
  width: 72%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #0b0f16;
  border-radius: 6px;
  display: none;
}
.page.show-mem .cell {
  background: var(--card);
}
.page.show-mem .cell.is-now {
  background: #2a2440;
}
.page.show-mem .cell__mem { display: block; }
.page.show-mem .cell__glyph { display: none; }
.cell__glyph-img {
  width: 1.55em;
  height: 1.55em;
  object-fit: contain;
  display: block;
}
.page.show-mem .cell__glyph-img { display: none; }
.cell__mark {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 0.85rem;
  font-weight: 900;
}
.cell.is-ok .cell__mark { color: var(--ok); }
.cell.is-bad .cell__mark { color: var(--bad); }
.cell__key {
  display: none;
  margin-top: 2px;
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--muted);
  line-height: 1;
}
.page.show-mem .cell__key {
  display: block;
}
.kb {
  flex: 0 0 auto;
  background: #10182a;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  padding: 6px 4px 8px;
}
.kb__row {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-bottom: 4px;
}
.kb__row--mid { padding: 0 4%; }
.kb__key {
  flex: 1 1 0;
  min-width: 0;
  min-height: 2.05rem;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 7px;
  background: linear-gradient(180deg, #2a3550, #1a2236);
  color: #eef3ff;
  font-weight: 900;
  font-size: 0.88rem;
  cursor: pointer;
}
.kb__key:active { filter: brightness(1.15); }
.kb__key.is-disabled {
  opacity: 0.35;
  cursor: default;
}
.legend {
  margin: 6px 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}
