:root {
  color-scheme: dark;
  --bg: #121414;
  --panel: #1d2220;
  --panel-strong: #252b28;
  --ink: #f4f5ef;
  --muted: #aab2aa;
  --line: rgba(244, 245, 239, 0.14);
  --mint: #5ee6a8;
  --amber: #ffd166;
  --coral: #ff7a6e;
  --sky: #83d7ff;
  --card-red: #e92b16;
  --card-cream: #fff0dc;
  --card-paper: #f8e5c9;
  --card-ink: #4d4036;
  --sauce: #b8957b;
  --dough: #e6c89d;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  --radius: 8px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(94, 230, 168, 0.11), transparent 34%),
    linear-gradient(315deg, rgba(255, 122, 110, 0.1), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Yu Gothic UI", sans-serif;
  letter-spacing: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(131, 215, 255, 0.8);
  outline-offset: 2px;
}

.orientation-note {
  display: none;
  position: fixed;
  inset: 10px 10px auto;
  z-index: 20;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 20, 20, 0.9);
  color: var(--amber);
  text-align: center;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.app-shell {
  width: 100vw;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.topbar,
.roster-panel,
.active-panel,
.side-panel,
.modal form {
  border: 1px solid var(--line);
  background: rgba(29, 34, 32, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 62px;
  border-radius: var(--radius);
  padding: 8px 12px;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--mint) 0 34%, transparent 35%),
    conic-gradient(from 20deg, var(--coral), var(--amber), var(--mint), var(--sky), var(--coral));
  border: 2px solid rgba(255, 255, 255, 0.18);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.26rem;
  line-height: 1.05;
}

h2 {
  font-size: 0.98rem;
}

.brand p,
.panel-head span,
.score-main small,
.card-meta span,
.history-line small,
.eyebrow {
  color: var(--muted);
}

.brand p {
  margin-top: 3px;
  font-size: 0.78rem;
}

.top-actions,
.panel-actions,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.active-panel,
.side-panel,
.roster-panel {
  min-height: 0;
  border-radius: var(--radius);
  padding: 12px;
  overflow: hidden;
}

.active-panel {
  display: grid;
  grid-template-rows: auto auto minmax(180px, 1fr) auto;
  gap: 12px;
  background:
    linear-gradient(180deg, rgba(233, 43, 22, 0.1), transparent 28%),
    var(--card-paper);
  color: #211813;
}

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

.roster-panel {
  width: min(520px, calc(100vw - 28px));
  max-height: min(720px, calc(100dvh - 28px));
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
}

.panel-head,
.active-user-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.panel-head {
  align-items: center;
}

.panel-head > div {
  min-width: 0;
}

.panel-head span {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
}

.eyebrow {
  display: block;
  font-size: 0.68rem;
  font-weight: 900;
}

#activeName {
  margin-top: 2px;
  color: #211813;
  font-size: clamp(1.45rem, 3.6vh, 2.35rem);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

#activeNote {
  margin-top: 5px;
  color: #7b6756;
  font-size: 0.86rem;
  min-height: 1.1em;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(104px, 0.18fr) 1fr;
  gap: 8px;
  align-items: stretch;
}

.score-main,
.card-meta {
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(124, 91, 63, 0.22);
  padding: 6px 8px;
}

.score-main {
  display: grid;
  place-items: center;
  text-align: center;
}

.score-main span {
  font-size: clamp(1.6rem, 5.5vh, 3.2rem);
  font-weight: 950;
  line-height: 0.94;
  color: var(--card-red);
}

.score-main small {
  margin-top: 1px;
  font-size: 0.58rem;
  font-weight: 900;
}

.card-meta {
  display: grid;
  align-content: center;
  gap: 3px;
}

.card-meta strong {
  font-size: 0.98rem;
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(124, 91, 63, 0.16);
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #5ba0dc, var(--card-red));
  transition: width 180ms ease;
}

.stamp-card {
  --stamp-columns: 7;
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  align-content: stretch;
  padding: clamp(34px, 7vh, 52px) clamp(14px, 2.2vw, 28px) clamp(24px, 5vh, 36px);
  border: 3px solid var(--card-red);
  border-radius: var(--radius);
  background: var(--card-cream);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.34);
}

.stamp-card::before,
.stamp-card::after {
  content: "";
  position: absolute;
  left: -18px;
  right: -18px;
  z-index: 0;
  height: clamp(22px, 5.5vh, 38px);
  pointer-events: none;
}

.stamp-card::before {
  top: 0;
  background:
    radial-gradient(circle at 48px 100%, var(--card-cream) 0 34px, transparent 35px) repeat-x,
    var(--card-red);
  background-size: 96px 100%;
}

.stamp-card::after {
  bottom: 0;
  background:
    radial-gradient(circle at 48px 0, var(--card-cream) 0 34px, transparent 35px) repeat-x,
    var(--card-red);
  background-size: 96px 100%;
}

.card-brand {
  position: absolute;
  top: clamp(8px, 1.8vh, 14px);
  left: 50%;
  z-index: 2;
  max-width: 100%;
  color: #050505;
  font-weight: 950;
  font-size: clamp(1.02rem, 3.2vh, 1.9rem);
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  text-shadow:
    3px 3px 0 #ffffff,
    -3px 3px 0 #ffffff,
    3px -3px 0 #ffffff,
    -3px -3px 0 #ffffff,
    0 4px 0 rgba(0, 0, 0, 0.16);
  transform: translateX(-50%) rotate(-1.5deg);
}

.card-range {
  position: absolute;
  right: 14px;
  top: 10px;
  z-index: 2;
  color: rgba(77, 64, 54, 0.7);
  font-size: 0.68rem;
  font-weight: 900;
}

.takoyaki-grid {
  position: relative;
  z-index: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--stamp-columns), minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(5px, 1.2vh, 12px) clamp(8px, 1.4vw, 18px);
  align-items: center;
  justify-items: center;
}

.stamp {
  position: relative;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 96px;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: rgba(77, 64, 54, 0.58);
  font-weight: 950;
  background:
    linear-gradient(180deg, rgba(185, 149, 123, 0.86) 0 48%, rgba(230, 200, 157, 0.88) 49% 100%);
  box-shadow:
    inset 0 -3px 0 rgba(124, 91, 63, 0.14),
    0 2px 0 rgba(124, 91, 63, 0.13);
  opacity: 0.55;
  transform: translateZ(0);
}

.stamp::before {
  content: "";
  position: absolute;
  left: 7%;
  right: 7%;
  top: 6%;
  height: 46%;
  border-radius: 58% 52% 44% 46%;
  background:
    radial-gradient(circle at 24% 20%, #f4b56e 0 3%, transparent 3.4%),
    radial-gradient(circle at 56% 14%, #f4b56e 0 2.8%, transparent 3.2%),
    radial-gradient(circle at 82% 30%, #f4b56e 0 2.8%, transparent 3.2%),
    linear-gradient(25deg, transparent 11%, #90c894 12% 15%, transparent 16% 100%),
    linear-gradient(72deg, transparent 21%, #90c894 22% 25%, transparent 26% 100%),
    linear-gradient(142deg, transparent 36%, #90c894 37% 40%, transparent 41% 100%),
    var(--sauce);
}

.stamp::after {
  content: "";
  position: absolute;
  left: 7%;
  right: 7%;
  top: 34%;
  height: 22%;
  border: 3px solid rgba(124, 91, 63, 0.32);
  border-top: 0;
  border-radius: 0 0 50% 50%;
  transform: rotate(-5deg);
}

.stamp.filled {
  opacity: 1;
  color: var(--card-ink);
  filter: saturate(1.06);
  box-shadow:
    inset 0 -4px 0 rgba(124, 91, 63, 0.17),
    0 4px 0 rgba(124, 91, 63, 0.16);
}

.stamp.next {
  opacity: 0.9;
  outline: 3px solid rgba(233, 43, 22, 0.7);
  outline-offset: 2px;
}

.stamp-number,
.stamp-date {
  position: relative;
  z-index: 1;
  display: block;
  color: currentColor;
  line-height: 1;
  letter-spacing: 0;
  text-shadow:
    0.08em 0.08em 0 rgba(255, 255, 255, 0.72),
    -0.05em -0.04em 0 rgba(255, 255, 255, 0.42);
}

.stamp-number {
  transform: translateY(5%);
  font-size: clamp(1rem, 5vh, 3.8rem);
}

.stamp-date {
  transform: rotate(-4deg);
  padding: 0.2em 0.18em;
  border-radius: 999px;
  color: #e92b16;
  background: rgba(255, 255, 255, 0.58);
  font-size: clamp(0.72rem, 2.4vh, 1.1rem);
  font-weight: 950;
}

.stamp.milestone-blue .stamp-number {
  color: #4f7fae;
}

.stamp.milestone-red .stamp-number {
  color: #e2674e;
}

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

.action-button {
  min-height: 74px;
  padding: 10px;
  border-radius: var(--radius);
  color: #111;
  text-align: left;
  display: grid;
  align-content: space-between;
  gap: 6px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.action-button span {
  display: block;
  font-weight: 900;
  font-size: clamp(0.88rem, 2.5vh, 1.1rem);
  overflow-wrap: anywhere;
}

.action-button strong {
  display: block;
  font-size: clamp(1.3rem, 4.8vh, 2.4rem);
  line-height: 1;
}

.action-button.visit {
  background: linear-gradient(145deg, var(--mint), #b8ffd9);
}

.action-button.special {
  background: linear-gradient(145deg, var(--sky), #d5f3ff);
}

.action-button.minus {
  background: linear-gradient(145deg, #ffb2aa, var(--coral));
}

.history-block {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.history-list,
.roster-list {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.history-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  margin-bottom: 6px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.055);
}

.history-line strong,
.user-row strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-line small,
.user-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.history-delta {
  font-weight: 950;
  color: var(--mint);
}

.history-delta.negative {
  color: var(--coral);
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.18);
}

.search-box span {
  color: var(--muted);
  font-size: 0.76rem;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.22);
  color: var(--ink);
}

.search-box input {
  border: 0;
  background: transparent;
}

input {
  height: 38px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  min-height: 170px;
  padding: 10px;
  line-height: 1.5;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.22);
}

.segmented button,
.tool-button,
.small-button,
.primary-button,
.danger-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius);
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
}

.segmented button {
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
}

.segmented button[aria-pressed="true"] {
  background: var(--panel-strong);
  color: var(--ink);
}

.tool-button,
.small-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  padding: 0 12px;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.74rem;
}

.primary-button {
  background: linear-gradient(135deg, var(--mint), #9cffcb);
  color: #0b2418;
  padding: 0 14px;
}

.user-switch-button {
  min-width: 150px;
  display: grid;
  place-items: center;
  gap: 2px;
  line-height: 1.05;
}

.user-switch-button span {
  font-size: 0.72rem;
}

.user-switch-button strong {
  display: block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.danger-button {
  background: rgba(255, 122, 110, 0.16);
  color: #ffd6d1;
  border: 1px solid rgba(255, 122, 110, 0.42);
  padding: 0 12px;
}

.icon-button {
  width: 38px;
  padding: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 1.2rem;
}

.user-row {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 54px;
  margin-bottom: 6px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  text-align: left;
}

.user-row[aria-current="true"] {
  border-color: rgba(94, 230, 168, 0.72);
  background: rgba(94, 230, 168, 0.13);
}

.rank-pill {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.point-badge {
  min-width: 46px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.15);
  color: var(--amber);
  text-align: center;
  font-weight: 900;
}

.modal {
  width: min(460px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
}

.modal.wide {
  width: min(560px, calc(100vw - 28px));
}

.modal.roster-modal {
  width: min(540px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.modal form {
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 12px;
}

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

.modal label {
  display: grid;
  gap: 5px;
}

.modal label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 30;
  max-width: calc(100vw - 24px);
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 20, 20, 0.95);
  color: var(--ink);
  box-shadow: var(--shadow);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > button {
    flex: 1 1 0;
  }

  .side-panel {
    max-height: none;
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  .orientation-note {
    display: block;
  }

  .app-shell {
    padding-top: 54px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar {
    min-height: 42px;
    padding-block: 4px;
    grid-template-columns: minmax(142px, 1fr) auto;
    gap: 8px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }

  h1 {
    font-size: 1rem;
  }

  .brand p {
    display: none;
  }

  .top-actions {
    gap: 5px;
  }

  .top-actions .tool-button {
    min-height: 32px;
    padding-inline: 8px;
    font-size: 0.78rem;
  }

  .user-switch-button {
    min-width: 132px;
    min-height: 34px;
    padding-inline: 10px;
  }

  .user-switch-button strong {
    max-width: 126px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .active-panel {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 4px;
    padding: 6px 10px;
  }

  .panel-head {
    min-height: 32px;
  }

  .panel-head .eyebrow {
    display: none;
  }

  .panel-head .tool-button {
    min-height: 32px;
    padding-inline: 10px;
    font-size: 0.8rem;
  }

  #activeName {
    font-size: 1.16rem;
  }

  #activeNote {
    display: none;
  }

  .score-row {
    grid-template-columns: minmax(64px, 0.1fr) 1fr;
    gap: 6px;
    height: 42px;
    min-height: 0;
  }

  .score-main,
  .card-meta {
    padding: 3px 8px;
  }

  .score-main span {
    font-size: 1.22rem;
  }

  .score-main small {
    display: none;
  }

  .card-meta {
    gap: 1px;
  }

  .card-meta strong {
    font-size: 0.86rem;
    line-height: 1;
  }

  .card-meta span {
    font-size: 0.82rem;
    line-height: 1.05;
  }

  .progress-track {
    height: 5px;
  }

  .stamp-card {
    padding: 20px 8px 12px;
  }

  .takoyaki-grid {
    gap: 2px clamp(8px, 1.35vw, 14px);
    align-items: stretch;
  }

  .stamp {
    max-height: none;
  }

  .stamp-number {
    font-size: clamp(0.92rem, 4.9vh, 2.15rem);
  }

  .stamp-date {
    font-size: clamp(0.62rem, 2.8vh, 1rem);
  }

  .card-brand {
    font-size: 0.98rem;
    text-shadow:
      2px 2px 0 #ffffff,
      -2px 2px 0 #ffffff,
      2px -2px 0 #ffffff,
      -2px -2px 0 #ffffff,
      0 3px 0 rgba(0, 0, 0, 0.16);
  }

  .card-range {
    display: none;
  }

  .quick-actions {
    gap: 6px;
  }

  .action-button {
    min-height: 42px;
    padding: 6px 8px;
    gap: 2px;
  }

  .action-button span {
    font-size: 0.76rem;
  }

  .action-button strong {
    font-size: 1.24rem;
  }
}
