:root {
  --paper: #f3ead8;
  --paper-deep: #e7dcc4;
  --card: #fbf6ec;
  --ink: #2c261d;
  --ink-soft: #5e5548;
  --muted: #8a7f6e;
  --rule: #dfd2b8;
  --rule-strong: #cbbfa4;
  --seal: #b54a3c;
  --seal-deep: #8e342a;
  --moss: #3d6a52;
  --gold: #c4a35a;
  --shadow: 0 10px 28px rgba(70, 52, 24, 0.08);
  --serif: "Noto Serif TC", "Songti TC", serif;
  --sans: "Noto Sans TC", "PingFang HK", "Hiragino Sans CNS", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* Author display rules (e.g. .form-stack) must not override the hidden attribute */
[hidden] {
  display: none !important;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #fff8ea 0%, transparent 50%),
    linear-gradient(180deg, #d9c9a8 0%, #cbb897 100%);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}

.notebook {
  display: flex;
  max-width: 480px;
  margin: 1.2rem auto;
  background: var(--paper);
  border-radius: 6px 14px 14px 6px;
  box-shadow:
    var(--shadow),
    inset 0 0 0 1px rgba(255, 255, 255, 0.45);
  min-height: calc(100vh - 2.4rem);
  min-height: calc(100dvh - 2.4rem);
  position: relative;
}

.notebook::before {
  content: "";
  position: absolute;
  inset: 0 0 0 18px;
  background-image: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 27px,
    rgba(196, 163, 90, 0.07) 28px
  );
  pointer-events: none;
  border-radius: inherit;
}

.binding {
  width: 18px;
  flex: 0 0 18px;
  background:
    repeating-linear-gradient(
      180deg,
      #7a2d26 0 10px,
      #8e342a 10px 22px,
      #5e211c 22px 24px
    );
  border-radius: 6px 0 0 6px;
  box-shadow: inset -4px 0 8px rgba(0, 0, 0, 0.18);
}

.page {
  flex: 1;
  padding: 1.6rem 1.35rem 1.1rem;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

.masthead {
  text-align: center;
  margin-bottom: 1.75rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px dashed var(--rule-strong);
}

.brand-kana {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  color: var(--seal);
  font-weight: 600;
}

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 2.15rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink);
}

.tagline {
  margin: 0.45rem 0 0;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.35rem 1rem;
  justify-items: center;
  padding: 0.4rem 0.2rem 1rem;
}

.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
  color: inherit;
  width: 100%;
  max-width: 140px;
  -webkit-user-select: none;
  user-select: none;
}

.app-tile:focus-visible {
  outline: 2px solid rgba(181, 74, 60, 0.45);
  outline-offset: 4px;
  border-radius: 12px;
}

.app-icon {
  width: 104px;
  height: 104px;
  border-radius: 22px;
  background:
    linear-gradient(160deg, #fffdf8 0%, var(--card) 55%, var(--paper-deep) 100%);
  border: 1px solid var(--rule-strong);
  box-shadow:
    0 6px 16px rgba(70, 52, 24, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  display: grid;
  place-items: center;
  font-size: 2.65rem;
  line-height: 1;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

a.app-tile:active .app-icon {
  transform: scale(0.94);
  box-shadow: 0 2px 8px rgba(70, 52, 24, 0.12);
}

.app-icon svg {
  display: block;
}

.app-label {
  font-family: var(--serif);
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.app-sub {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.app-tile.is-empty {
  pointer-events: none;
  opacity: 0.55;
}

.empty-slot {
  background: transparent;
  border: 1.5px dashed var(--rule-strong);
  box-shadow: none;
  color: var(--muted);
}

.empty-slot .plus {
  font-size: 1.8rem;
  font-weight: 300;
  color: var(--muted);
}

.app-label.muted {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.86rem;
  color: var(--muted);
  letter-spacing: 0;
}

.preview-note {
  margin: 0.5rem 0 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}

.preview-note a {
  color: var(--seal);
  text-decoration: none;
  border-bottom: 1px dotted rgba(181, 74, 60, 0.45);
}

.preview-note a:hover {
  border-bottom-style: solid;
}

.foot {
  margin-top: auto;
  padding-top: 1.5rem;
  text-align: center;
}

.foot p {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

@media (min-width: 420px) {
  .app-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 640px) {
  .notebook {
    max-width: 560px;
    margin: 1.6rem auto;
  }
  .binding {
    width: 22px;
    flex-basis: 22px;
  }
  .notebook::before {
    inset: 0 0 0 22px;
  }
  .app-icon {
    width: 112px;
    height: 112px;
    border-radius: 24px;
  }
}


/* —— Account / settings page —— */

.foot a {
  color: var(--seal);
  text-decoration: none;
  border-bottom: 1px dotted rgba(181, 74, 60, 0.45);
}

.foot a:hover {
  border-bottom-style: solid;
}

.masthead-account {
  text-align: left;
  position: relative;
}

.masthead-account .brand-kana,
.masthead-account h1,
.masthead-account .tagline {
  text-align: center;
}

.masthead-account h1 {
  font-size: 1.55rem;
  letter-spacing: 0.08em;
}

.back-link {
  display: inline-block;
  margin-bottom: 0.85rem;
  font-size: 0.82rem;
  color: var(--seal);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.back-link:hover {
  text-decoration: underline;
}

.account-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 0.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1rem 1.05rem 1.1rem;
  box-shadow: 0 4px 14px rgba(70, 52, 24, 0.05);
}

.card-quiet {
  background: transparent;
  box-shadow: none;
  border-style: dashed;
}

.card-title {
  margin: 0 0 0.75rem;
  font-family: var(--serif);
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed var(--rule);
}

.status-badge {
  margin: 0 0 0.85rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
  background: var(--paper-deep);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.optional {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.72rem;
}

.field-static {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
}

.field input,
.field select {
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  padding: 0.62rem 0.75rem;
  min-height: 44px;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}

.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: rgba(181, 74, 60, 0.55);
  box-shadow: 0 0 0 3px rgba(181, 74, 60, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-radius: 10px;
  padding: 0.65rem 1.1rem;
  min-height: 44px;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(180deg, var(--seal) 0%, var(--seal-deep) 100%);
  color: #fffdf8;
  box-shadow: 0 4px 12px rgba(142, 52, 42, 0.22);
  border-color: var(--seal-deep);
}

.btn-secondary {
  background: var(--paper);
  color: var(--ink-soft);
  border-color: var(--rule-strong);
  width: 100%;
}

.btn-secondary:hover {
  background: var(--paper-deep);
}

.btn-ghost {
  background: transparent;
  color: var(--seal);
  border-color: var(--rule-strong);
  min-height: 36px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.btn-ghost:hover {
  background: rgba(181, 74, 60, 0.06);
}

.linked-apps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.linked-apps li {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.35rem;
  border-bottom: 1px dashed var(--rule);
}

.linked-apps li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.linked-icon {
  font-size: 1.55rem;
  width: 2.2rem;
  text-align: center;
  flex-shrink: 0;
}

.linked-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.linked-name {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.linked-desc {
  font-size: 0.72rem;
  color: var(--muted);
}

.privacy-text {
  margin: 0;
  font-size: 0.84rem;
  color: var(--ink-soft);
  line-height: 1.65;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #fbf6ec;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.7rem 1.15rem;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(44, 38, 29, 0.28);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: calc(100vw - 2rem);
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 380px) {
  .masthead-account h1 {
    font-size: 1.35rem;
  }
  .page {
    padding-left: 1.1rem;
    padding-right: 1.05rem;
  }
}


/* —— Admin console —— */
.admin-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.admin-stat-card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.75rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.admin-stat-label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.admin-stat-value {
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.admin-note {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.55;
}
.admin-user-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.admin-user-item {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.7rem 0.55rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
}
.admin-user-email {
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-all;
}
.admin-user-sub {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
.admin-user-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.admin-role-select {
  flex: 1;
  font: inherit;
  font-size: 0.9rem;
  min-height: 44px;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  background: #fffdf8;
  appearance: none;
  -webkit-appearance: none;
}
.admin-save-role {
  flex-shrink: 0;
  min-width: 4.5rem;
  padding-left: 0.85rem;
  padding-right: 0.85rem;
}
.admin-role-legend {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.84rem;
  color: var(--ink-soft);
  line-height: 1.7;
}
.membership-tier {
  display: inline-block;
  margin-top: 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--seal);
  background: rgba(181, 74, 60, 0.08);
  border: 1px solid rgba(181, 74, 60, 0.22);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
}
.admin-entry {
  margin-top: 0.65rem;
}

.membership-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.85rem;
  margin: 0.35rem 0 0.75rem;
}
.membership-row .membership-tier {
  margin: 0;
}
.admin-entry-link {
  font-size: 0.92rem;
  font-weight: 600;
  color: #8b3a2f;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.admin-entry-link:hover {
  color: #5c241c;
}


/* —— Admin service usage —— */
.usage-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}
.usage-group {
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  padding: 0.65rem 0.7rem 0.55rem;
}
.usage-group-title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--seal);
  cursor: pointer;
  list-style: none;
}
.usage-group summary.usage-group-title::-webkit-details-marker { display: none; }
.usage-group summary.usage-group-title::before {
  content: "▸ ";
  color: var(--muted);
  font-weight: 700;
}
.usage-group[open] summary.usage-group-title::before { content: "▾ "; }
.usage-group-body { margin-top: 0.45rem; }
.usage-placeholder { margin: 0.2rem 0 0; }
.usage-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr 0.9fr;
  gap: 0.35rem 0.55rem;
  align-items: baseline;
  padding: 0.28rem 0;
  border-top: 1px dashed var(--rule);
  font-size: 0.8rem;
}
.usage-row:first-of-type {
  border-top: none;
}
.usage-metric {
  color: var(--ink-soft);
  font-weight: 600;
}
.usage-value {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.usage-note {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
}
.usage-status {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0 0 0.35rem;
}
.usage-status.is-warn {
  color: #8b3a2f;
}
.usage-status.is-ok {
  color: #2f6b4f;
}
@media (max-width: 560px) {
  .usage-row {
    grid-template-columns: 1fr;
    gap: 0.1rem;
    padding: 0.4rem 0;
  }
}

/* Admin rescue panel */
.rescue-panel {
  margin-top: 1rem;
  padding: 0.85rem 0.7rem;
  border: 1px solid var(--rule-strong);
  border-radius: 12px;
  background: #fffdf8;
}
.rescue-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}
.rescue-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}
.rescue-actions {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0 0.75rem;
}
.rescue-section {
  margin-top: 0.85rem;
}
.rescue-section-title {
  margin: 0 0 0.4rem;
  font-size: 0.88rem;
  font-weight: 650;
}
.rescue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.rescue-item {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
}
.rescue-item-meta {
  flex: 1;
  min-width: 12rem;
}
.rescue-item-title {
  font-weight: 600;
  font-size: 0.86rem;
}
.rescue-item-sub {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.12rem;
}
.admin-rescue-btn {
  flex-shrink: 0;
  white-space: nowrap;
}
.admin-user-actions {
  flex-wrap: wrap;
}
