:root {
  --accent: #64f2be;
  --bg: #0f1020;
  --bg-top: #313a79;
  --danger: #ff6b6b;
  --font-scale: 1;
  --muted: #9ca3d0;
  --panel: #1f2140;
  --panel-alt: #2b2f59;
  --pixel: #6f77a8;
  --text: #ecf2ff;
}

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

html,
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, var(--bg-top), var(--bg) 48%);
  color: var(--text);
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: calc(16px * var(--font-scale));
  line-height: 1.6;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
input,
select {
  font: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: calc(14px * var(--font-scale));
}

h2 {
  font-size: calc(13px * var(--font-scale));
  margin-bottom: 10px;
}

.label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: calc(9px * var(--font-scale));
}

.microcopy,
.hint {
  color: var(--muted);
  font-size: calc(8px * var(--font-scale));
  line-height: 1.8;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 440px;
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 14px calc(env(safe-area-inset-bottom) + 80px);
}

.app-shell.is-locked .top-bar,
.app-shell.is-locked .content,
.app-shell.is-locked .tabbar {
  opacity: 0.18;
  pointer-events: none;
  user-select: none;
  filter: blur(5px);
}

.top-bar {
  display: flex;
  align-items: center;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--panel);
}

.pixel-border {
  border: 3px solid var(--pixel);
  border-radius: 8px;
  box-shadow: 4px 4px 0 #00000055;
}

.icon-btn,
.action-btn,
.primary,
.secondary,
.danger,
.tabbar button,
.language-btn,
.font-scale-btn {
  border: 2px solid var(--pixel);
  border-radius: 8px;
  background: var(--panel-alt);
  color: var(--text);
  padding: 10px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
}

.secondary {
  background: transparent;
}

.button-link {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-decoration: none;
}

.balance-card {
  margin-bottom: 12px;
  padding: 14px;
  background: linear-gradient(145deg, #39408c 0%, var(--panel) 70%);
}

.welcome-card,
.asset-list,
.history,
.history-summary,
.history-toolbar,
.profile-panel,
.profile-summary,
.pixel-form,
.receive-card,
.virtual-card {
  padding: 12px;
  background: var(--panel);
}

.welcome-card {
  margin-bottom: 12px;
}

.history-toolbar,
.history-summary,
.history {
  margin-bottom: 12px;
}

.welcome-name {
  margin-bottom: 6px;
  font-size: calc(12px * var(--font-scale));
}

.balance {
  margin: 6px 0 12px;
  font-size: calc(20px * var(--font-scale));
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.month-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.month-scroll::-webkit-scrollbar {
  display: none;
}

.month-chip {
  flex: 0 0 auto;
  border: 2px solid var(--pixel);
  border-radius: 999px;
  background: var(--panel-alt);
  color: var(--text);
  padding: 8px 12px;
  white-space: nowrap;
}

.month-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f1020;
}

.month-chip.current {
  box-shadow: inset 0 0 0 1px #ffffff30;
}

.chip {
  padding: 5px 7px;
  border-radius: 6px;
  background: #00000040;
  font-size: calc(8px * var(--font-scale));
}

.toggle-chip {
  border: 2px solid var(--pixel);
  color: var(--text);
  font: inherit;
}

.toggle-chip.active {
  background: var(--accent);
  color: #0f1020;
}

.positive {
  color: var(--accent);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.action-btn {
  min-height: 56px;
}

.asset-list ul,
.history {
  margin: 0;
  padding: 0;
  list-style: none;
}

.asset-item,
.history li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed #ffffff22;
  font-size: calc(9px * var(--font-scale));
}

.asset-item:last-child,
.history li:last-child {
  border-bottom: none;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.pixel-form,
.startup-form {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  font-size: calc(9px * var(--font-scale));
}

input,
select {
  width: 100%;
  border: 2px solid var(--pixel);
  border-radius: 6px;
  background: #0f122f;
  color: #f2f5ff;
  padding: 10px;
}

.primary {
  background: #1f6f57;
  color: #effff9;
}

.danger {
  width: 100%;
  margin-top: 10px;
  background: #5f1d2b;
  color: #ffeef2;
}

.receive-card code {
  display: block;
  margin-top: 8px;
  word-break: break-all;
}

.qr-fake {
  width: 128px;
  height: 128px;
  margin-top: 12px;
  border: 3px solid var(--pixel);
  background-image:
    linear-gradient(45deg, #000 25%, transparent 25%),
    linear-gradient(-45deg, #000 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #000 75%),
    linear-gradient(-45deg, transparent 75%, #000 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.virtual-card {
  background: linear-gradient(130deg, #5317be, #2a53e6);
}

.card-number {
  margin: 16px 0;
  font-size: calc(12px * var(--font-scale));
}

.card-row {
  display: flex;
  justify-content: space-between;
  font-size: calc(8px * var(--font-scale));
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 20px));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px;
  background: var(--panel);
}

.tabbar button {
  padding: 8px 4px;
  font-size: calc(8px * var(--font-scale));
}

.tabbar button.active {
  outline: 2px solid var(--accent);
}

.startup-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: start;
  padding: 20px 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #0a0c1cdc;
  backdrop-filter: blur(8px);
  touch-action: pan-y;
}

.startup-card {
  width: min(420px, 100%);
  margin: auto auto 0;
  padding: 20px 16px;
  background: var(--panel);
}

.startup-copy {
  margin-bottom: 16px;
  color: var(--muted);
  font-size: calc(9px * var(--font-scale));
  line-height: 1.8;
}

.profile-copy {
  margin-bottom: 16px;
}

.startup-actions {
  display: grid;
  gap: 10px;
}

.font-scale-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.font-scale-grid {
  display: grid;
  gap: 10px;
}

.font-scale-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.schedule-stack {
  display: grid;
  gap: 10px;
}

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

.schedule-choice {
  margin: 0;
  padding: 0;
  border: 0;
}

.schedule-choice legend {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: calc(9px * var(--font-scale));
}

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

.choice-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px;
  border: 2px solid var(--pixel);
  border-radius: 6px;
  background: #0f122f;
}

.choice-option input {
  width: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
}

.schedule-variation {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.font-scale-btn {
  display: grid;
  gap: 6px;
  text-align: left;
}

.font-scale-btn.selected {
  border-color: var(--accent);
}

.font-scale-hint {
  color: var(--muted);
  font-size: calc(8px * var(--font-scale));
  line-height: 1.8;
}

.font-scale-preview {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: linear-gradient(145deg, #39408c 0%, var(--panel) 72%);
}

.font-scale-preview-title {
  font-size: calc(12px * var(--font-scale));
  line-height: 1.7;
}

.font-scale-preview-copy {
  font-size: calc(9px * var(--font-scale));
  line-height: 1.8;
}

.font-scale-preview-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 8px 10px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: #1f6f57;
  color: #effff9;
  font-size: calc(8px * var(--font-scale));
}

.language-grid {
  display: grid;
  gap: 10px;
}

.language-btn {
  display: grid;
  gap: 6px;
  text-align: left;
}

.language-btn.selected {
  border-color: var(--accent);
}

.language-native {
  color: var(--muted);
  font-size: calc(8px * var(--font-scale));
}

.profile-panel {
  margin-bottom: 12px;
}

.profile-summary {
  background: linear-gradient(145deg, #39408c 0%, var(--panel) 72%);
}

.field-hint {
  color: var(--muted);
  font-size: calc(8px * var(--font-scale));
  line-height: 1.8;
}

.settings-font-scale {
  display: grid;
  gap: 8px;
}

.settings-months {
  display: grid;
  gap: 8px;
}

.value-stack {
  text-align: right;
}

.value-stack small {
  color: var(--muted);
}

.history-empty {
  display: block !important;
  text-align: left;
  border-bottom: none !important;
}

.form-error {
  min-height: 12px;
  color: var(--danger);
  font-size: calc(8px * var(--font-scale));
}

.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border: 4px solid #ffffff24;
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

#toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: #10142ecc;
  color: #fff;
  padding: 8px 10px;
  font-size: calc(8px * var(--font-scale));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#toast.show {
  opacity: 1;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 360px) {
  .balance {
    font-size: calc(16px * var(--font-scale));
  }

  .tabbar button {
    font-size: calc(7px * var(--font-scale));
  }

  .choice-grid,
  .schedule-grid,
  .font-scale-grid.compact {
    grid-template-columns: 1fr;
  }
}
