:root {
  color-scheme: dark;
  --ink: #f5f7f5;
  --muted: rgba(245, 247, 245, 0.58);
  --line: rgba(255, 255, 255, 0.14);
  --glass: rgba(11, 15, 15, 0.56);
  --glass-strong: rgba(9, 12, 12, 0.82);
  --field: rgba(255, 255, 255, 0.07);
  --accent: #4ee1c1;
  --hot: #ff765f;
  --gold: #f0bd53;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.36);
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #151817;
  --muted: rgba(21, 24, 23, 0.58);
  --line: rgba(16, 25, 23, 0.14);
  --glass: rgba(250, 252, 249, 0.60);
  --glass-strong: rgba(252, 253, 250, 0.88);
  --field: rgba(255, 255, 255, 0.52);
  --accent: #087e72;
  --hot: #d85b43;
  --gold: #b88419;
  --shadow: 0 28px 90px rgba(27, 42, 37, 0.18);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  background: #090b0b;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button, textarea, input, output { font: inherit; }

button, .qr-bottom a {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
  cursor: pointer;
}

button:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 2px;
}

#fluid {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  background: #090b0b;
  image-rendering: auto;
}

#fluid.fallback {
  background:
    linear-gradient(135deg, #0d2926, #15110f 48%, #301913 78%, #101212);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: rgba(3, 6, 6, 0.045);
  backdrop-filter: saturate(108%);
}

.app-shell {
  width: min(1120px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 0 24px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.identity {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 4px 10px 4px 4px;
  background: transparent;
  border-color: transparent;
  min-width: 0;
  width: fit-content;
}

.identity-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--glass-strong);
  font-size: 11px;
  font-weight: 900;
}

.identity-name {
  font-size: 14px;
  font-weight: 760;
}

.top-actions, .actions, .qr-bottom > div {
  display: flex;
  align-items: center;
  gap: 7px;
}

.top-actions { flex: 0 0 auto; }

.wechat-entry {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 760;
}

.wechat-icon {
  position: relative;
  width: 24px;
  height: 19px;
}

.wechat-icon i {
  position: absolute;
  display: block;
  width: 15px;
  height: 12px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.wechat-icon i:first-child { left: 0; top: 0; }
.wechat-icon i:last-child { right: 0; bottom: 0; }

.icon-button {
  width: 40px;
  height: 40px;
  font-size: 17px;
}

.workbench {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 94px);
  padding-top: 12px;
}

.tool-dock, .workspace {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.tool-dock {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 9px;
}

.tab {
  width: 54px;
  height: 46px;
  padding: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.tab:hover, .tab.is-active, .actions button:hover, .icon-button:hover, .wechat-entry:hover {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--line));
  background: color-mix(in srgb, var(--accent) 13%, var(--field));
  color: var(--ink);
}

.dock-divider {
  display: block;
  width: 36px;
  height: 1px;
  margin: 3px auto;
  background: var(--line);
}

.workspace {
  min-width: 0;
  width: 100%;
  min-height: 600px;
  padding: clamp(14px, 2.6vw, 26px);
}

.panel { display: none; }

.panel.is-active {
  display: grid;
  grid-template-rows: auto minmax(190px, 1fr) auto;
  gap: 14px;
  min-height: 100%;
}

#time.is-active, #random.is-active {
  grid-template-rows: auto auto minmax(150px, 1fr);
}

.tool-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.tool-head strong {
  font-size: clamp(30px, 5vw, 58px);
  line-height: 1;
}

.actions { flex-wrap: wrap; justify-content: flex-end; }

.actions button, .arrows button, .qr-top button, .qr-bottom button, .qr-bottom a {
  display: grid;
  place-items: center;
  min-width: 42px;
  height: 40px;
  padding: 0 10px;
  font-weight: 850;
  text-decoration: none;
}

textarea, .output, .output-box {
  width: 100%;
  min-height: 180px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  resize: vertical;
  line-height: 1.58;
}

input[type="text"], input[type="datetime-local"] {
  min-width: 0;
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
}

input[type="datetime-local"] { color-scheme: inherit; }

.output, .output-box {
  display: block;
  min-height: 90px;
  overflow: auto;
  white-space: pre-wrap;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
}

.time-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.field-row > span, .length-control > span, .result-field > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
}

.result-output {
  min-height: 150px;
  margin: 0;
  line-height: 1.9;
}

.text-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}

.text-stats output {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
  padding: 13px 14px 0;
}

.text-stats output + output { border-left: 1px solid var(--line); }
.text-stats strong { overflow: hidden; font-size: 18px; text-overflow: ellipsis; }
.text-stats span { color: var(--muted); font-size: 11px; }

.random-controls {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.length-control {
  display: grid;
  grid-template-columns: 34px minmax(100px, 1fr) 34px;
  align-items: center;
  gap: 10px;
}

.length-control output {
  text-align: right;
  font-weight: 850;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.option-toggles {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.option-toggles label {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 38px;
  cursor: pointer;
}

.option-toggles input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.option-toggles span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.option-toggles input:checked + span {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--line));
  background: color-mix(in srgb, var(--accent) 14%, var(--field));
  color: var(--ink);
}

.option-toggles input:focus-visible + span {
  outline: 2px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 2px;
}

.random-results {
  display: grid;
  align-content: start;
  gap: 10px;
}

.result-field {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 8px 9px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.result-field output {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.result-field button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
}

.score {
  display: grid;
  place-items: center;
  min-width: 58px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  font-weight: 850;
}

.game-panel { grid-template-rows: auto minmax(0, 1fr) auto; }

.puzzle-board, .board-2048 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  aspect-ratio: 1;
  width: min(100%, 430px);
  margin: auto;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
}

.tile, .cell-2048 {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  font-size: clamp(18px, 5vw, 31px);
  font-weight: 900;
}

.tile.empty { opacity: 0; pointer-events: none; }
.cell-2048[data-v="0"] { color: transparent; }
.cell-2048[data-v="2"], .cell-2048[data-v="4"] { background: color-mix(in srgb, var(--accent) 15%, var(--field)); }
.cell-2048[data-v="8"], .cell-2048[data-v="16"], .cell-2048[data-v="32"] { background: color-mix(in srgb, var(--hot) 21%, var(--field)); }
.cell-2048:not([data-v="0"]):not([data-v="2"]):not([data-v="4"]):not([data-v="8"]):not([data-v="16"]):not([data-v="32"]) { background: color-mix(in srgb, var(--gold) 28%, var(--field)); }

.arrows {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: min(100%, 430px);
  margin: 0 auto;
}

.wechat-modal[hidden] { display: none; }

.wechat-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.54);
  backdrop-filter: blur(10px);
}

.qr-dialog {
  position: relative;
  width: min(390px, 100%);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
}

.qr-top, .qr-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.qr-top { padding: 2px 2px 10px 8px; color: var(--muted); font-size: 13px; font-weight: 760; }
.qr-top button { width: 36px; height: 36px; }

.qr-dialog img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #fff;
}

.qr-bottom { padding: 11px 2px 0 8px; }
.qr-bottom strong { font-size: 14px; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  min-width: 54px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--ink);
  color: var(--glass-strong);
  font-size: 13px;
  font-weight: 850;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 720px) {
  .app-shell { width: calc(100vw - 16px); max-width: none; padding-top: 8px; }
  .topbar { position: sticky; top: 8px; z-index: 10; }
  .identity-name { max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
  .wechat-entry span:last-child { display: none; }
  .wechat-entry { width: 40px; padding: 0; justify-content: center; }
  .workbench { grid-template-columns: minmax(0, 1fr); width: 100%; min-width: 0; min-height: auto; }
  .tool-dock { position: sticky; top: 70px; z-index: 9; display: flex; overflow-x: auto; padding: 7px; scrollbar-width: none; }
  .tool-dock::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 50px; width: 50px; height: 42px; }
  .dock-divider { flex: 0 0 1px; width: 1px; height: 28px; margin: 7px 2px; }
  .workspace { width: 100%; min-width: 0; min-height: calc(100vh - 142px); overflow: hidden; padding: 14px; }
  .panel.is-active { min-height: 530px; }
  .time-fields { grid-template-columns: minmax(0, 1fr); }
  .random-controls { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .option-toggles { justify-content: flex-start; }
}

@media (max-width: 430px) {
  .identity { padding-right: 6px; }
  .identity-name { max-width: 78px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  textarea, .output, .output-box { min-height: 150px; }
  .field-row { grid-template-columns: 52px minmax(0, 1fr); }
  .text-stats output { grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 10px 7px 0; text-align: center; }
  .text-stats strong { font-size: 15px; }
  .result-field { grid-template-columns: 40px minmax(0, 1fr) auto auto; }
}

@media (prefers-reduced-motion: no-preference) {
  button, a, .tile, .cell-2048 { transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, color 140ms ease; }
  button:hover, .qr-bottom a:hover, .tile:not(.empty):hover { transform: translateY(-1px); }
  button:active, .qr-bottom a:active { transform: scale(0.96); }
}
