:root {
  --bg: #f5f5f4;
  --panel: #fafafa;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #3b82f6;
  --shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-card: 0 6px 18px rgba(0, 0, 0, 0.08);
  --flip-anim-ms: 240ms;
  --flip-anim-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --flip-anim-shadow-frame: 0 10px 24px rgba(0, 0, 0, 0.14);
  --flip-anim-shadow-card: 0 10px 24px rgba(0, 0, 0, 0.16);
  --flip-anim-accent: rgba(59, 130, 246, 0.28);
  --radius: 12px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  padding: 0 var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-panel);
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar-center {
  flex: 1;
  justify-content: center;
  font-size: 14px;
  color: var(--muted);
}

.deck-display {
  display: flex;
  align-items: baseline;
  gap: 6px;
  cursor: pointer;
}

.deck-name {
  font-weight: 600;
  font-size: 16px;
}

.deck-version {
  font-size: 12px;
  color: var(--muted);
}

.deck-warning {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.deck-warning[hidden] {
  display: none;
}

.content {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
  flex: 1;
}

.card-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.card-stage {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
}

.card-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.preview-column {
  align-items: stretch;
  gap: var(--space-1);
  min-width: 260px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  width: 100%;
  min-height: 32px;
}

.card-header .btn {
  text-transform: none;
  letter-spacing: normal;
}

.card-hint-inline {
  font-size: 12px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: normal;
}

.sidebar {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: var(--space-2);
  box-shadow: var(--shadow-panel);
}

.panel-header {
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.card-frame {
  --card-frame-padding: var(--space-2);
  width: min(
    calc(var(--card-width, 448px) + (var(--card-frame-padding) * 2)),
    80vw
  );
  aspect-ratio: var(--card-cols, 12) / var(--card-rows, 16);
  background: var(--panel);
  border-radius: 16px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--card-frame-padding);
  transition: transform 150ms ease, box-shadow 150ms ease;
  cursor: pointer;
}

.card-frame.preview {
  cursor: default;
}

.card-frame.preview:hover {
  transform: none;
  box-shadow: var(--shadow-panel);
}

.card-frame:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-frame:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
}

.card-frame.is-disabled {
  pointer-events: none;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-panel);
  opacity: 0.7;
}

.card {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(var(--card-cols, 12), 1fr);
  grid-template-rows: repeat(var(--card-rows, 16), 1fr);
  padding: var(--card-pad-y, var(--space-1)) var(--card-pad-x, var(--space-1));
  gap: 0;
}

.card::before,
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.card::before {
  opacity: 0;
  z-index: 1;
  background: rgba(59, 130, 246, 0.14);
}

.card::after {
  z-index: 2;
  opacity: 0;
  transform: translateX(-120%);
  background: linear-gradient(
    120deg,
    rgba(255, 255, 255, 0) 12%,
    rgba(147, 197, 253, 0.38) 40%,
    rgba(255, 255, 255, 0.62) 54%,
    rgba(191, 219, 254, 0.3) 68%,
    rgba(255, 255, 255, 0) 88%
  );
}

@keyframes cardFrameFlipPulse {
  0% {
    transform: translateY(0) scale(1);
    box-shadow: var(--shadow-panel);
  }
  45% {
    transform: translateY(-4px) scale(1.012);
    box-shadow: var(--flip-anim-shadow-frame);
  }
  100% {
    transform: translateY(0) scale(1);
    box-shadow: var(--shadow-panel);
  }
}

@keyframes cardSurfaceFlipCue {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
    box-shadow: inset 0 0 0 0 rgba(59, 130, 246, 0), var(--shadow-card);
  }
  45% {
    transform: translateY(-2px) scale(1.008);
    opacity: 0.97;
    box-shadow: inset 0 0 0 3px var(--flip-anim-accent), var(--flip-anim-shadow-card);
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
    box-shadow: inset 0 0 0 0 rgba(59, 130, 246, 0), var(--shadow-card);
  }
}

@keyframes cardSurfaceTint {
  0% {
    opacity: 0;
  }
  35% {
    opacity: 0.26;
  }
  100% {
    opacity: 0;
  }
}

@keyframes cardSurfaceSheen {
  0% {
    opacity: 0;
    transform: translateX(-120%);
  }
  35% {
    opacity: 0.58;
  }
  100% {
    opacity: 0;
    transform: translateX(120%);
  }
}

.card-frame.is-flip-animating {
  animation: cardFrameFlipPulse var(--flip-anim-ms) var(--flip-anim-ease);
  will-change: transform, box-shadow;
}

.card.is-flip-animating {
  animation: cardSurfaceFlipCue var(--flip-anim-ms) var(--flip-anim-ease);
  will-change: transform, opacity, box-shadow;
}

.card.is-flip-animating::before {
  animation: cardSurfaceTint var(--flip-anim-ms) var(--flip-anim-ease);
}

.card.is-flip-animating::after {
  animation: cardSurfaceSheen var(--flip-anim-ms) var(--flip-anim-ease);
}

.card-placeholder {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: calc(14px * var(--card-text-scale, 1));
  text-align: center;
}

.card-placeholder.card-error {
  color: #b91c1c;
  font-weight: 600;
}

.card-block {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  border-bottom: 1px solid var(--border);
}

.card-block:last-child {
  border-bottom: none;
}

.block-title {
  font-size: calc(11px * var(--card-text-scale, 1));
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: center;
  margin-bottom: 4px;
}

.kv-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
}

.kv-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}

.kv-list--left .kv-item {
  justify-content: flex-start;
}

.kv-list--left .kv-label {
  min-width: var(--kv-label-width, 3ch);
}

.kv-list--left .kv-value {
  text-align: left;
}

.kv-item--solo {
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.kv-label {
  font-size: calc(12px * var(--card-text-scale, 1));
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kv-value {
  font-size: calc(14px * var(--card-text-scale, 1));
  font-weight: 500;
}

.table-wrap {
  width: 100%;
  overflow: hidden;
}

.card-table {
  width: 100%;
  border-collapse: collapse;
  font-size: calc(12px * var(--card-text-scale, 1));
}

.card-table thead th {
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: calc(11px * var(--card-text-scale, 1));
  padding: var(--table-pad-y, 4px) var(--table-pad-x, 4px);
  border-bottom: 1px solid var(--border);
}

.card-table tbody th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: var(--table-pad-y, 4px) var(--table-pad-x, 4px);
  border-bottom: 1px solid var(--border);
}

.card-table thead th:first-child,
.card-table tbody th:first-child {
  min-width: var(--table-rowhead-width, auto);
  padding-left: var(--table-rowhead-pad-x, var(--table-pad-x, 4px));
  padding-right: var(--table-rowhead-pad-x, var(--table-pad-x, 4px));
}

.card-table--rowhead thead th:first-child {
  text-align: left;
}

.card-table td {
  text-align: center;
  padding: var(--table-pad-y, 4px) var(--table-pad-x, 4px);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

.card-table tbody tr:last-child th,
.card-table tbody tr:last-child td {
  border-bottom: none;
}


.card-actions {
  display: flex;
  gap: var(--space-1);
  justify-content: center;
  width: 100%;
}


.deck-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.deck-list.is-disabled {
  pointer-events: none;
  opacity: 0.6;
}

.deck-list.is-disabled .deck-item {
  cursor: not-allowed;
}

.deck-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  border: 0;
  width: 100%;
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  text-align: left;
  font: inherit;
  color: inherit;
  appearance: none;
}

.deck-item.is-error {
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 4px;
}

.deck-item-error {
  font-size: 12px;
  color: #b91c1c;
  line-height: 1.3;
}

.deck-item:hover {
  background: #f3f4f6;
}

.deck-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.deck-item:disabled {
  cursor: not-allowed;
  opacity: 1;
}

.deck-item.is-active {
  background: var(--accent);
  color: #fff;
}

.deck-item.is-active .deck-item-version {
  color: rgba(255, 255, 255, 0.9);
}

.deck-item-version {
  font-size: 12px;
  color: var(--muted);
}

.toggle-block {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.history-list.is-disabled {
  pointer-events: none;
  opacity: 0.6;
}

.history-item {
  border: none;
  background: transparent;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.history-item:hover {
  background: #f3f4f6;
}

.history-item.is-active {
  background: #e5e7eb;
  color: var(--text);
}

.history-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.history-item:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.history-item strong {
  color: var(--text);
  font-weight: 600;
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #d1d5db;
  border-radius: 999px;
  transition: background 150ms ease;
}

.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 150ms ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.switch input:disabled + .slider {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}


.icon {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  color: currentColor;
  box-sizing: border-box;
}


.icon-reset {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-right-color: transparent;
  border-radius: 50%;
  transform: rotate(-45deg);
}

.icon-refresh {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  position: relative;
}

.icon-refresh::after {
  content: "";
  position: absolute;
  right: -2px;
  top: 1px;
  width: 0;
  height: 0;
  border-left: 6px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(10deg);
}

.muted {
  color: var(--muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: #fff;
  border-radius: 16px;
  padding: var(--space-3);
  width: min(360px, 90vw);
  box-shadow: var(--shadow-card);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-1);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-body {
  color: var(--text);
  font-size: 14px;
}

.modal-body a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.modal-body a:hover {
  text-decoration: underline;
}

.modal.is-about {
  text-align: left;
}

.modal.is-about .modal-title {
  text-align: left;
}

.about-list {
  display: grid;
  gap: var(--space-1);
}

.about-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--space-1);
  align-items: center;
}

.about-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.about-value {
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .card-frame.is-flip-animating,
  .card.is-flip-animating {
    animation: none;
  }

  .card-frame.is-flip-animating {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.22);
  }

  .card.is-flip-animating {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.22), var(--shadow-card);
    opacity: 1;
    transform: none;
  }

  .card.is-flip-animating::after {
    animation: none;
    opacity: 0;
    transform: translateX(0);
  }

  .card.is-flip-animating::before {
    animation: none;
    opacity: 0.14;
  }
}

@media (max-width: 520px) {
  .about-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .content {
    flex-direction: column;
  }

  .card-stage {
    flex-direction: column;
    align-items: center;
  }

  .sidebar {
    width: 100%;
  }

  .topbar {
    padding: 0 var(--space-2);
    flex-wrap: wrap;
    height: auto;
    gap: var(--space-1);
  }

  .topbar-center {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }
}
