:root {
  --ink: #18201d;
  --muted: #69736e;
  --paper: #fbfaf6;
  --panel: rgba(255, 255, 255, 0.86);
  --line: rgba(24, 32, 29, 0.14);
  --accent: #2f6f73;
  --yes: #16a05f;
  --yes-bg: #d8f3df;
  --no: #d92f3d;
  --no-bg: #ffe0e3;
  --reroll: #d99b13;
  --reroll-bg: #fff0bf;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: #ece7dc;
}

button,
input,
textarea {
  font: inherit;
}

.app {
  min-height: 100vh;
  transition: background-color 280ms ease;
}

.dice-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(360px, 1fr);
}

.app[data-view="history"] .dice-screen {
  display: none;
}

.app[data-view="dice"] .history-screen {
  display: none;
}

.app[data-result="idle"] {
  background: linear-gradient(135deg, #f4f0e7 0%, #dfe8e4 100%);
}

.app[data-result="yes"] {
  background: var(--yes-bg);
}

.app[data-result="no"] {
  background: var(--no-bg);
}

.app[data-result="reroll"] {
  background: var(--reroll-bg);
}

.app[data-view="history"] {
  background: linear-gradient(135deg, #f4f0e7 0%, #dfe8e4 100%);
}

.panel {
  min-height: 100vh;
  padding: 48px 34px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
  overflow-y: auto;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.tab-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}

.tab-button.is-active {
  color: #fff;
  background: var(--ink);
}

.clock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.88rem;
  line-height: 1.35;
}

.clock strong {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 900;
  text-align: right;
}

.clock[hidden] {
  display: none;
}

.header {
  display: grid;
  gap: 8px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 9em;
  font-size: clamp(2rem, 3.8vw, 3.6rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
}

.field {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 700;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 15px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 111, 115, 0.12);
}

.selector {
  display: grid;
  gap: 14px;
}

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

.selector-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
}

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.number-option {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  border: 1px solid rgba(24, 32, 29, 0.12);
  border-radius: 8px;
  color: var(--ink);
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 34%),
    linear-gradient(145deg, #ffffff 0%, #f7f4ee 100%);
  box-shadow:
    0 8px 18px rgba(24, 32, 29, 0.06),
    inset 0 -5px 0 rgba(24, 32, 29, 0.04);
  font-size: 0.92rem;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease;
}

.number-option:hover {
  transform: translateY(-2px);
  border-color: rgba(47, 111, 115, 0.36);
  box-shadow:
    0 12px 24px rgba(24, 32, 29, 0.1),
    inset 0 -5px 0 rgba(24, 32, 29, 0.04);
}

.number-option.is-selected {
  border-color: var(--accent);
  color: var(--accent);
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 34%),
    linear-gradient(145deg, #f8fffb 0%, #d9f1df 100%);
  box-shadow:
    0 12px 26px rgba(22, 160, 95, 0.18),
    0 0 0 3px rgba(47, 111, 115, 0.14),
    inset 0 -5px 0 rgba(22, 160, 95, 0.1);
}

.mini-die {
  position: relative;
  width: 46px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #ffffff;
  box-shadow:
    0 5px 12px rgba(24, 32, 29, 0.12),
    inset 0 -3px 0 rgba(24, 32, 29, 0.06);
}

.mini-die i {
  position: absolute;
  width: 8px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0;
}

.mini-die i:nth-child(1) {
  top: 22%;
  left: 22%;
}

.mini-die i:nth-child(2) {
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
}

.mini-die i:nth-child(3) {
  top: 22%;
  right: 22%;
}

.mini-die i:nth-child(4) {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.mini-die i:nth-child(5) {
  bottom: 22%;
  left: 22%;
}

.mini-die i:nth-child(6) {
  bottom: 22%;
  left: 50%;
  transform: translateX(-50%);
}

.mini-die i:nth-child(7) {
  right: 22%;
  bottom: 22%;
}

.face-1 i:nth-child(4),
.face-2 i:nth-child(1),
.face-2 i:nth-child(7),
.face-3 i:nth-child(1),
.face-3 i:nth-child(4),
.face-3 i:nth-child(7),
.face-4 i:nth-child(1),
.face-4 i:nth-child(3),
.face-4 i:nth-child(5),
.face-4 i:nth-child(7),
.face-5 i:nth-child(1),
.face-5 i:nth-child(3),
.face-5 i:nth-child(4),
.face-5 i:nth-child(5),
.face-5 i:nth-child(7),
.face-6 i:nth-child(1),
.face-6 i:nth-child(3),
.face-6 i:nth-child(5),
.face-6 i:nth-child(7),
.face-6 i:nth-child(2),
.face-6 i:nth-child(6) {
  opacity: 1;
}

.face-6 i:nth-child(2) {
  top: 50%;
  left: 22%;
  transform: translateY(-50%);
}

.face-6 i:nth-child(6) {
  top: 50%;
  right: 22%;
  bottom: auto;
  left: auto;
  transform: translateY(-50%);
}

.number-option.is-selected .mini-die {
  background: var(--accent);
}

.number-option.is-selected .mini-die i {
  background: #fff;
}

.number-option.is-reroll {
  border-color: var(--reroll);
  color: #8b5f00;
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 34%),
    linear-gradient(145deg, #fffaf0 0%, #ffe7a3 100%);
  box-shadow:
    0 12px 26px rgba(217, 155, 19, 0.2),
    0 0 0 3px rgba(217, 155, 19, 0.16),
    inset 0 -5px 0 rgba(217, 155, 19, 0.14);
}

.number-option.is-reroll .mini-die {
  background: var(--reroll);
}

.number-option.is-reroll .mini-die i {
  background: #fff;
}

.number-option.is-reroll::after {
  content: "重投";
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  color: #fff;
  background: var(--reroll);
  font-size: 0.72rem;
  font-weight: 1000;
}

.roll-button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 17px 18px;
  color: #fff;
  background: #18201d;
  font-size: 1.04rem;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background-color 160ms ease;
}

.roll-button:hover {
  transform: translateY(-2px);
}

.roll-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 88px 38px 64px;
  overflow: hidden;
  perspective: 1100px;
}

.dice-wrap {
  display: grid;
  place-items: center;
  width: min(44vw, 360px);
  min-width: 240px;
  aspect-ratio: 1;
}

.dice {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 28px;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0) 34%),
    linear-gradient(145deg, #ffffff 0%, #f4f1eb 58%, #ded8ce 100%);
  box-shadow:
    0 26px 70px rgba(24, 32, 29, 0.22),
    0 6px 0 rgba(24, 32, 29, 0.1),
    inset 0 -18px 28px rgba(24, 32, 29, 0.12),
    inset 0 10px 22px rgba(255, 255, 255, 0.82);
  transform: rotate(0deg);
}

.dice.is-rolling {
  animation: tumble 680ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.pip {
  position: absolute;
  width: 18%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 36% 30%, #4c5751 0%, #18201d 58%, #0a0e0c 100%);
  box-shadow: inset 0 3px 5px rgba(255, 255, 255, 0.22);
  opacity: 0;
}

.pip-1 {
  top: 18%;
  left: 18%;
}

.pip-2 {
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
}

.pip-3 {
  top: 18%;
  right: 18%;
}

.pip-4 {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.pip-5 {
  bottom: 18%;
  left: 18%;
}

.pip-6 {
  bottom: 18%;
  left: 50%;
  transform: translateX(-50%);
}

.pip-7 {
  right: 18%;
  bottom: 18%;
}

.dice[data-face="1"] .pip-4,
.dice[data-face="2"] .pip-1,
.dice[data-face="2"] .pip-7,
.dice[data-face="3"] .pip-1,
.dice[data-face="3"] .pip-4,
.dice[data-face="3"] .pip-7,
.dice[data-face="4"] .pip-1,
.dice[data-face="4"] .pip-3,
.dice[data-face="4"] .pip-5,
.dice[data-face="4"] .pip-7,
.dice[data-face="5"] .pip-1,
.dice[data-face="5"] .pip-3,
.dice[data-face="5"] .pip-4,
.dice[data-face="5"] .pip-5,
.dice[data-face="5"] .pip-7,
.dice[data-face="6"] .pip-1,
.dice[data-face="6"] .pip-3,
.dice[data-face="6"] .pip-5,
.dice[data-face="6"] .pip-7,
.dice[data-face="6"] .pip-2,
.dice[data-face="6"] .pip-6 {
  opacity: 1;
}

.dice[data-face="6"] .pip-2 {
  top: 50%;
  left: 18%;
  transform: translateY(-50%);
}

.dice[data-face="6"] .pip-6 {
  top: 50%;
  right: 18%;
  bottom: auto;
  left: auto;
  transform: translateY(-50%);
}

.result-word {
  position: absolute;
  color: transparent;
  font-size: clamp(3.4rem, 9vw, 8.8rem);
  font-weight: 1000;
  line-height: 0.8;
  letter-spacing: 0;
  text-transform: uppercase;
  user-select: none;
  opacity: 0;
  transform: scale(0.9);
  transition:
    color 220ms ease,
    opacity 220ms ease,
    transform 220ms ease;
}

.result-word-top {
  top: 36px;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
}

.result-word-left {
  left: 38px;
  bottom: 38px;
}

.result-word-right {
  right: 38px;
  bottom: 38px;
}

.app[data-result="yes"] .result-word,
.app[data-result="no"] .result-word,
.app[data-result="reroll"] .result-word {
  opacity: 1;
  transform: scale(1);
}

.app[data-result="yes"] .result-word-top,
.app[data-result="no"] .result-word-top,
.app[data-result="reroll"] .result-word-top {
  transform: translateX(-50%) scale(1);
}

.app[data-result="yes"] .result-word {
  color: var(--yes);
}

.app[data-result="no"] .result-word {
  color: var(--no);
}

.app[data-result="reroll"] .result-word {
  color: var(--reroll);
}

.status {
  position: absolute;
  right: 38px;
  bottom: 26px;
  left: 38px;
  margin: 0;
  color: rgba(24, 32, 29, 0.72);
  text-align: center;
  font-weight: 800;
}

.history-screen {
  min-height: 100vh;
  padding: 44px min(6vw, 72px);
  background: rgba(255, 255, 255, 0.74);
}

.history-shell {
  display: grid;
  gap: 22px;
  max-width: 980px;
  margin: 0 auto;
}

.history-page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.history-page-head h1 {
  max-width: none;
}

.history-time {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.history-item {
  position: relative;
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  overflow: hidden;
}

.history-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  width: 100%;
  border: 0;
  padding: 14px 16px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.history-summary > span:first-child {
  min-width: 0;
}

.history-chevron {
  align-self: center;
  color: var(--muted);
  font-weight: 900;
  transform: rotate(0deg);
  transition: transform 160ms ease;
}

.history-item.is-open .history-chevron {
  transform: rotate(90deg);
}

.history-title {
  display: block;
  margin: 0;
  font-weight: 900;
  line-height: 1.35;
}

.history-meta {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.history-outcome {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.history-outcome span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.follow-mark {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  color: #fff;
  background: #aeb8b2;
  font-size: 0.9rem;
  font-weight: 1000;
  line-height: 1;
}

.follow-mark.followed {
  background: var(--yes);
}

.follow-mark.not-followed {
  background: var(--no);
}

.history-feedback {
  display: none;
  gap: 10px;
  padding: 0 16px 16px;
}

.history-item.is-open .history-feedback {
  display: grid;
}

.history-result {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  min-height: 24px;
  border-radius: 6px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 1000;
  text-transform: uppercase;
}

.history-result.yes {
  background: var(--yes);
}

.history-result.no {
  background: var(--no);
}

.feedback-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.feedback-row.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.feedback-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.feedback-button.is-active {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.feedback-button.danger.is-active {
  border-color: var(--no);
  background: var(--no);
}

.feedback-note {
  width: 100%;
  min-height: 56px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.feedback-note:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 111, 115, 0.12);
}

.history-confirm-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-button {
  min-width: 88px;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  color: #fff;
  background: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.delete-history-button {
  display: none;
  min-width: 88px;
  border: 1px solid rgba(217, 47, 61, 0.28);
  border-radius: 8px;
  padding: 9px 16px;
  color: var(--no);
  background: #fff;
  font-weight: 900;
  cursor: pointer;
}

.app[data-delete-mode="true"] .delete-history-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.history-item > .delete-history-button {
  position: absolute;
  top: 14px;
  right: 46px;
  min-width: 64px;
  padding: 7px 12px;
  font-size: 0.82rem;
}

.app[data-delete-mode="true"] .history-confirm-row .delete-history-button {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 32, 29, 0.42);
  backdrop-filter: blur(8px);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(92vw, 420px);
  display: grid;
  gap: 24px;
  padding: 28px;
  border-radius: 8px;
  background: #fffaf0;
  box-shadow: 0 28px 80px rgba(24, 32, 29, 0.28);
  text-align: center;
}

.modal-card h2 {
  font-size: 1.35rem;
  line-height: 1.35;
}

@keyframes tumble {
  0% {
    transform: rotate(0deg) scale(1);
  }
  35% {
    transform: rotate(22deg) scale(0.94);
  }
  70% {
    transform: rotate(-18deg) scale(1.04);
  }
  100% {
    transform: rotate(0deg) scale(1);
  }
}

@media (max-width: 760px) {
  .dice-screen {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
    padding: 28px 20px 24px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  h1 {
    max-width: 11em;
    font-size: 2.25rem;
  }

  .roll-button {
    margin-top: 2px;
  }

  .stage {
    min-height: 58vh;
    padding: 72px 20px 86px;
  }

  .dice-wrap {
    width: min(72vw, 290px);
    min-width: 210px;
  }

  .dice {
    border-radius: 22px;
  }

  .result-word-top {
    top: 24px;
  }

  .result-word-left {
    left: 20px;
    bottom: 34px;
  }

  .result-word-right {
    right: 20px;
    bottom: 34px;
  }

  .status {
    right: 20px;
    bottom: 14px;
    left: 20px;
  }

  .feedback-row {
    grid-template-columns: 1fr;
  }

  .feedback-row.two {
    grid-template-columns: 1fr;
  }

  .history-screen {
    padding: 28px 20px;
  }

  .history-page-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
