:root {
  --bg: #f7f7f7;
  --surface: #ffffff;
  --surface-2: #f2f2f2;
  --border: #d8d8d8;
  --border-strong: #c7c7c7;
  --text-main: #202020;
  --text-soft: #6c6c6c;
  --button: #2f2f2f;
  --button-hover: #1f1f1f;
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-main);
  font-family: "Outfit", system-ui, sans-serif;
}

.app-shell {
  width: min(1240px, 96vw);
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.25rem 1rem 2rem;
  position: relative;
}

.settings-shell {
  justify-content: flex-start;
  padding-top: 5.4rem;
}

.top-corner-controls {
  position: absolute;
  top: 1rem;
  left: 1rem;
  display: grid;
  gap: 0.35rem;
}

.top-corner-controls label {
  font-size: 0.75rem;
  color: #666;
}

.dataset-row {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.page-chip {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 0.9rem;
}

.top-right-nav {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
}

select,
.btn,
.field input,
.field textarea {
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: inherit;
}

select {
  min-width: 220px;
  height: 36px;
  padding: 0 0.6rem;
  font-size: 0.9rem;
  color: var(--text-main);
  background: #fff;
}

.machine {
  width: min(1160px, 95vw);
  min-height: 490px;
  border: 2px solid #cdcdcd;
  border-radius: 18px;
  background: var(--surface);
  padding: 1.2rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.reels-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.reel-card {
  min-height: 380px;
  border: 1px solid #cfcfcf;
  border-radius: 12px;
  background: #fcfcfc;
  overflow: hidden;
  position: relative;
}

.reel-header {
  margin: 0;
  height: 56px;
  display: grid;
  place-items: center;
  text-align: center;
  letter-spacing: 0.04em;
  font-size: 1rem;
  color: #3d3d3d;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.reel-window {
  position: absolute;
  inset: 56px 0 0;
  overflow: hidden;
}

.reel-window::before,
.reel-window::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 24%;
  z-index: 3;
  pointer-events: none;
}

.reel-window::before {
  top: 0;
  background: linear-gradient(to bottom, #fcfcfc 10%, transparent);
}

.reel-window::after {
  bottom: 0;
  background: linear-gradient(to top, #fcfcfc 10%, transparent);
}

.reel-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  will-change: transform;
}

.track-word {
  display: grid;
  place-items: center;
  height: 68px;
  margin: 0 12px;
  border-radius: 9px;
  border: 1px solid #d9d9d9;
  color: #4b4b4b;
  background: #f3f3f3;
  font-size: clamp(1.1rem, 1.8vw, 1.35rem);
  font-weight: 600;
}

.center-marker {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 50%;
  height: 68px;
  transform: translateY(-50%);
  border: 2px solid #8a8a8a;
  border-radius: 10px;
  pointer-events: none;
  z-index: 2;
}

.reel-card.is-spinning .center-marker {
  border-style: dashed;
}

.reel-card.is-spinning .reel-track {
  filter: blur(0.35px);
}

.reel-card.is-stopped {
  animation: settle 250ms ease;
}

.action-controls {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  width: 100%;
}

.btn {
  height: 42px;
  padding: 0 1.2rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn.subtle {
  background: #f8f8f8;
  color: #333;
}

.btn.primary,
.btn.danger {
  background: var(--button);
  color: #fff;
  border-color: #202020;
  min-width: 120px;
}

.btn.primary:hover,
.btn.danger:hover {
  background: var(--button-hover);
}

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

.icon-link {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: #2b2b2b;
  text-decoration: none;
  font-size: 1.45rem;
  line-height: 1;
  box-shadow: var(--shadow);
  transition: background 0.2s ease, transform 0.15s ease;
}

.icon-link:hover {
  background: #f3f3f3;
}

.icon-link:active {
  transform: translateY(1px);
}

.settings-page-grid {
  width: min(1320px, 96vw);
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.panel {
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sidebar-panel {
  overflow: hidden;
}

.editor-panel {
  min-width: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.15rem 1.15rem 0;
}

.sidebar-header {
  align-items: center;
}

.editor-header {
  align-items: center;
}

.panel-title {
  margin: 0;
  font-size: 1.1rem;
}

.panel-subtitle {
  margin: 0.25rem 0 0;
  color: var(--text-soft);
  font-size: 0.92rem;
}

.panel-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.save-status {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fafafa;
  color: #3c3c3c;
  font-size: 0.9rem;
  white-space: nowrap;
}

.save-status.is-dirty {
  background: #fff3d6;
  border-color: #e4c56f;
}

.selected-file-path {
  margin: 0.2rem 0 0;
  color: var(--text-soft);
  font-size: 0.9rem;
  word-break: break-all;
}

.dataset-list {
  display: grid;
  gap: 0.65rem;
  padding: 1rem 1.15rem 1.15rem;
}

.dataset-item {
  width: 100%;
  text-align: left;
  background: #fbfbfb;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
  display: grid;
  gap: 0.2rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.dataset-item:hover {
  background: #f5f5f5;
}

.dataset-item.is-selected {
  border-color: #7d7d7d;
  background: #f0f0f0;
}

.dataset-item-title {
  font-weight: 700;
  color: #1f1f1f;
}

.dataset-item-meta {
  color: var(--text-soft);
  font-size: 0.88rem;
  word-break: break-all;
}

.editor-form {
  display: grid;
  gap: 1rem;
  padding: 1rem 1.15rem 1.15rem;
}

.form-section {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  background: #fcfcfc;
  display: grid;
  gap: 0.9rem;
}

.section-title {
  margin: 0;
  font-size: 1rem;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.field-grid {
  display: grid;
  gap: 0.85rem;
}

.field-grid.two-columns {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 0.38rem;
}

.field span {
  font-size: 0.9rem;
  color: #4a4a4a;
}

.field input,
.field textarea {
  width: 100%;
  padding: 0.75rem 0.8rem;
  font-size: 0.95rem;
  color: var(--text-main);
  background: #fff;
  resize: vertical;
}

.field textarea {
  min-height: 110px;
}

.categories-list {
  display: grid;
  gap: 0.9rem;
}

.category-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  padding: 0.9rem;
  display: grid;
  gap: 0.8rem;
}

.category-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.category-card-header h4 {
  margin: 0;
  font-size: 1rem;
}

.category-grid {
  display: grid;
  gap: 0.85rem;
}

.empty-note {
  padding: 1rem;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: #fafafa;
  color: var(--text-soft);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.22);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
}

.modal.is-hidden {
  display: none;
}

.modal-card {
  width: min(640px, 100%);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.16);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

@keyframes settle {
  0% {
    transform: scale(0.992);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 980px) {
  .settings-page-grid {
    grid-template-columns: 1fr;
  }

  .field-grid.two-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    justify-content: flex-start;
    padding-top: 5.8rem;
  }

  .top-corner-controls {
    position: fixed;
    left: 0.6rem;
    top: 0.6rem;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem;
    z-index: 20;
  }

  .top-right-nav {
    position: fixed;
    top: 0.6rem;
    right: 0.6rem;
    z-index: 20;
  }

  select {
    min-width: 176px;
  }

  .machine {
    min-height: 420px;
  }

  .reel-card {
    min-height: 300px;
  }

  .panel-header,
  .category-card-header,
  .section-row,
  .panel-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .save-status {
    justify-content: center;
  }
}