:root {
  --paper: #f2eee5;
  --paper-deep: #e4dccd;
  --ink: #1c2420;
  --muted: #6e746d;
  --rule: #c8c0b0;
  --green: #174d3a;
  --green-soft: #dbe8df;
  --amber: #b4751c;
  --red: #9d332b;
  --white: #fffdf8;
  --shadow: 0 20px 50px -30px rgb(28 36 32 / 45%);
  --display: "Iowan Old Style", "Songti SC", "STSong", serif;
  --body: "Avenir Next", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --mono: "DIN Alternate", "IBM Plex Mono", "SFMono-Regular", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: var(--body);
  background:
    radial-gradient(circle at 85% 2%, rgb(180 117 28 / 13%), transparent 30rem),
    linear-gradient(160deg, #f8f4eb 0%, var(--paper) 55%, #e9e1d2 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}

.shell {
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(42px, env(safe-area-inset-bottom));
}

.masthead {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 2px 24px;
}

.seal {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--green);
  border-radius: 50%;
  color: var(--green);
  font-family: var(--display);
  font-size: 23px;
  box-shadow: inset 0 0 0 4px var(--paper), inset 0 0 0 5px rgb(23 77 58 / 35%);
}

.eyebrow,
.panel-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(28px, 8vw, 38px);
  font-weight: 600;
  letter-spacing: -0.04em;
}

h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.panel,
.identity-card {
  border: 1px solid rgb(28 36 32 / 14%);
  border-radius: 22px 22px 30px 22px;
  background: rgb(255 253 248 / 78%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel {
  padding: 24px 20px;
}

.login-panel {
  animation: rise 520ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.lede {
  margin: 8px 0 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

input {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 13px;
  outline: 0;
  color: var(--ink);
  background: rgb(255 255 255 / 58%);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input:focus {
  border-color: var(--green);
  background: var(--white);
  box-shadow: 0 0 0 4px rgb(23 77 58 / 9%);
}

.code-input {
  font-family: var(--mono);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-align: center;
}

.captcha-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 10px;
  align-items: end;
}

.captcha-image {
  height: 50px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 13px;
  color: var(--muted);
  background: var(--white);
}

.captcha-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.primary-button,
.mini-button,
.text-button {
  border: 0;
  border-radius: 999px;
  font-weight: 700;
  transition: transform 150ms ease, background 150ms ease, color 150ms ease;
}

.primary-button {
  min-height: 52px;
  padding: 0 22px;
  color: #fff;
  background: var(--green);
  box-shadow: 0 12px 30px -18px rgb(23 77 58 / 95%);
}

.primary-button:active,
.mini-button:active,
.text-button:active {
  transform: scale(0.97);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.mini-button {
  padding: 8px 12px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 11px;
}

.text-button {
  padding: 8px 2px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 12px;
  line-height: 1.5;
}

.identity-card {
  padding: 22px 20px 18px;
  animation: rise 460ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.identity-row,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.ip-ticket {
  display: grid;
  gap: 5px;
  margin: 20px 0 16px;
  padding: 17px 16px 15px;
  border: 1px dashed rgb(23 77 58 / 50%);
  border-radius: 15px;
  background: var(--green-soft);
}

.ip-ticket span {
  color: var(--green);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.ip-ticket strong {
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: clamp(24px, 7vw, 34px);
  letter-spacing: -0.03em;
}

.sync-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgb(180 117 28 / 12%);
}

.sync-dot.ok {
  background: var(--green);
  box-shadow: 0 0 0 4px rgb(23 77 58 / 12%);
}

.mono {
  font-family: var(--mono);
}

.action-panel,
.grant-section {
  margin-top: 16px;
}

.grant-note {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.grant-note span {
  padding: 6px 9px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
}

.grant-section {
  padding: 4px 2px;
}

.grant-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.grant-card {
  position: relative;
  padding: 16px;
  overflow: hidden;
  border: 1px solid rgb(28 36 32 / 13%);
  border-radius: 17px;
  background: rgb(255 253 248 / 72%);
  animation: rise 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.grant-card::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  content: "";
  background: var(--amber);
}

.grant-card.active::before {
  background: var(--green);
}

.grant-card.expired::before {
  background: var(--rule);
}

.grant-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.grant-address {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 22px;
}

.grant-label {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status-chip {
  flex: none;
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--amber);
  background: rgb(180 117 28 / 11%);
  font-size: 10px;
  font-weight: 800;
}

.status-chip.active {
  color: var(--green);
  background: var(--green-soft);
}

.status-chip.expired {
  color: var(--muted);
  background: var(--paper-deep);
}

.grant-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
}

.grant-actions {
  display: flex;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 10px;
}

.empty-state {
  padding: 34px 18px;
  border: 1px dashed var(--rule);
  border-radius: 16px;
  color: var(--muted);
  font-family: var(--display);
  font-size: 18px;
  text-align: center;
}

.history-box {
  margin-top: 16px;
  padding: 4px 2px;
}

.history-box summary {
  padding: 13px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

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

.history-row {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid rgb(28 36 32 / 9%);
  color: var(--muted);
  font-size: 11px;
}

.totp-dialog {
  width: min(calc(100% - 28px), 430px);
  padding: 0;
  border: 1px solid rgb(28 36 32 / 17%);
  border-radius: 24px;
  color: var(--ink);
  background: var(--white);
  box-shadow: 0 30px 100px -30px rgb(0 0 0 / 50%);
}

.totp-dialog::backdrop {
  background: rgb(20 28 24 / 55%);
  backdrop-filter: blur(4px);
}

.totp-dialog form {
  display: grid;
  gap: 15px;
  padding: 24px 20px 20px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.dialog-actions .primary-button {
  min-height: 44px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 18px;
  z-index: 30;
  max-width: 520px;
  margin: auto;
  padding: 13px 16px;
  border-radius: 13px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  font-size: 12px;
  text-align: center;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
