:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e4e8ef;
  --text: #1f2933;
  --muted: #6b7785;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --accent-hover: #1d4ed8;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, .12);
  --radius: 14px;
  --radius-sm: 10px;
  --maxw: 1120px;
}

* { box-sizing: border-box; }

/* ---------- dark theme ---------- */
:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-soft: #1e3a8a;
  --accent-hover: #60a5fa;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 6px 20px rgba(0,0,0,.5);
}
:root[data-theme="dark"] body { background: var(--bg); }
:root[data-theme="dark"] .result,
:root[data-theme="dark"] .out-card,
:root[data-theme="dark"] .search-box { background: #0f172a; }
:root[data-theme="dark"] .chip { background: var(--surface); }
:root[data-theme="dark"] .clock-big,
:root[data-theme="dark"] .big-result { color: #f1f5f9; }

/* ---------- header controls ---------- */
.header-controls { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.lang-sel {
  width: auto;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
}
.theme-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.theme-btn:hover { border-color: var(--accent); }


html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 20px;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-logo { font-size: 24px; }
.brand-name { letter-spacing: .5px; }

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  max-width: 520px;
}
.search-box:focus-within { border-color: var(--accent); background: #fff; }
.search-icon { opacity: .6; }
.search-box input {
  border: none;
  outline: none;
  background: transparent;
  width: 100%;
  font-size: 15px;
  color: var(--text);
}

.cat-nav {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 20px 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.cat-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.cat-pill:hover { color: var(--text); border-color: #c7d0db; }
.cat-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- Main ---------- */
.app-main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.section-title {
  font-size: 22px;
  font-weight: 800;
  margin: 8px 0 4px;
}
.section-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #c7d0db;
}
.card-icon { font-size: 30px; line-height: 1; }
.card-title { font-weight: 700; font-size: 16px; }
.card-desc { color: var(--muted); font-size: 13px; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}

/* ---------- Tool view ---------- */
.tool-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 18px;
}
.tool-back:hover { border-color: #c7d0db; text-decoration: none; }

.tool-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.tool-head .tool-icon { font-size: 34px; }
.tool-head h1 { font-size: 24px; margin: 0; }
.tool-head .tool-tag {
  margin-left: auto;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
}
.tool-desc { color: var(--muted); margin: 0 0 22px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

/* ---------- Form controls ---------- */
.row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 160px; }
label { font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 110px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: #c7d0db; background: var(--bg); }
.btn.danger { background: #dc2626; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

.result {
  margin-top: 16px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  word-break: break-all;
  white-space: pre-wrap;
}
.result:empty { display: none; }

.output-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.out-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.out-card .k { font-size: 12px; color: var(--muted); }
.out-card .v { font-size: 18px; font-weight: 700; word-break: break-all; }

.ref-table { width: 100%; border-collapse: collapse; font-family: var(--font, system-ui, sans-serif); white-space: normal; margin-top: 0; }
.ref-table th, .ref-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
.ref-table th { color: var(--muted); font-weight: 600; background: var(--surface); }
.ref-table code { background: var(--surface); padding: 2px 6px; border-radius: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; }

.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ---------- Emoji Picker ---------- */
.emoji-cat-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.emoji-cat { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 5px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.emoji-cat:hover { border-color: var(--accent); }
.emoji-cat.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 4px; max-height: 420px; overflow-y: auto; padding: 4px; }
.emoji-item { font-size: 24px; cursor: pointer; padding: 4px 5px; border-radius: 6px; line-height: 1; user-select: none; }
.emoji-item:hover { background: var(--surface); transform: scale(1.15); transition: transform .1s; }

/* ---------- Clocks ---------- */
.clock-big {
  font-variant-numeric: tabular-nums;
  font-size: clamp(40px, 9vw, 84px);
  font-weight: 800;
  text-align: center;
  letter-spacing: 2px;
}
.clock-date { text-align: center; color: var(--muted); margin-bottom: 10px; }
canvas.analog { display: block; margin: 0 auto; max-width: 100%; }

/* ---------- Dice / coin ---------- */
.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  min-height: 120px;
  margin: 10px 0 18px;
}
.die {
  width: 76px; height: 76px;
  display: grid; place-items: center;
  font-size: 38px; font-weight: 800;
  background: #fff; border: 2px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
}
.coin {
  width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 30px; font-weight: 800; color: #fff;
  background: radial-gradient(circle at 30% 30%, #fbbf24, #d97706);
  box-shadow: var(--shadow-md);
}
.big-result { text-align: center; font-size: 28px; font-weight: 800; min-height: 36px; }

/* ---------- Wheel ---------- */
.wheel-wrap { display: flex; gap: 24px; flex-wrap: wrap; align-items: center; justify-content: center; }
#wheelCanvas { max-width: 100%; }
.wheel-side { min-width: 220px; flex: 1; }

/* ---------- Symbols / kaomoji ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 18px;
  transition: all .12s ease;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip small { font-size: 11px; color: var(--muted); display: block; }

/* ---------- Footer ---------- */
.site-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 20px 48px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}
.site-footer .muted { opacity: .8; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2933; color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; opacity: 0;
  transition: all .2s ease; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  .header-inner { flex-wrap: wrap; }
  .search-box { max-width: none; order: 3; flex-basis: 100%; }
}
