﻿* {
  box-sizing: border-box;
}

:root {
  --bg: #2d353f;
  --panel: #e9edf2;
  --panel-soft: #f7f9fc;
  --line: #c7ced8;
  --line-strong: #98a3af;
  --text: #1f242a;
  --muted: #5c6774;
  --accent: #505a68;
  --success: #2f9e44;
  --warning: #d97706;
  --danger: #b91c1c;
}

body {
  margin: 0;
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}

.app-container {
  min-height: 100vh;
  padding: 18px 16px 28px;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 20px;
  border: 1px solid rgba(171, 181, 192, 0.45);
  border-radius: 16px;
  background: var(--panel);
  display: grid;
  gap: 14px;
  box-shadow: 0 14px 34px rgba(10, 14, 20, 0.3);
}

.header {
  position: sticky;
  top: 0;
  z-index: 1000;
  left: 0;
  right: 0;
  background: rgb(248, 249, 255);
  border: 1px solid rgba(175, 184, 194, 0.5);
  border-top: 0;
  border-radius: 0 0 15px 15px;
  padding: 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  width: 100%;
}

.header-content {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  box-sizing: border-box;
  padding: 30px 36px 26px;
  position: relative;
  text-align: center;
}

.header-content h1 {
  font-size: 2em;
  font-weight: 800;
  color: #3c4652;
  margin-bottom: 8px;
  margin-top: 8px;
}

.subtitle {
  color: #586371;
  font-size: 1.08em;
  margin: 0;
}

.header-guide-list {
  list-style: none;
  padding-left: 0;
  margin: 0.5em 0 0;
}

.back-btn {
  position: absolute;
  top: 10px;
  left: 15px;
  z-index: 10;
  font-size: 1.08em;
  color: #546170;
  font-weight: 600;
  background: none;
  border: none;
  outline: none;
  padding: 6px 18px;
  min-width: 90px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.18s, background 0.18s;
  box-shadow: none;
  border-radius: 50px;
  text-decoration: none;
  line-height: 1.2;
}

.back-btn:hover {
  transform: scale(1.08);
  background: #eceff3;
  text-decoration: none;
}

.top-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.side-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-soft);
}

.side-toggle.is-hidden {
  display: none;
}

.edit-mode-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.edit-mode-actions.is-hidden {
  display: none;
}

.toggle-btn {
  border: 0;
  background: #d4dae2;
  color: #313a45;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
}

.toggle-btn.active {
  background: var(--accent);
  color: #f3f4f6;
}

.sim-view {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  min-height: 340px;
  display: grid;
  place-items: center;
  min-width: 0;
  overflow: hidden;
}

.face-stage {
  width: min(100%, 720px);
  display: grid;
  place-items: center;
  min-height: 268px;
  padding: 12px 0;
}

.face-shell {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: clamp(44px, 6vw, 74px);
  align-items: center;
  padding: 18px 26px 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 56px;
  background: linear-gradient(180deg, #4b5564 0%, #2a313b 42%, #161c24 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    inset 0 -18px 28px rgba(0, 0, 0, 0.35),
    0 18px 28px rgba(0, 0, 0, 0.2);
}

.matrix-frame {
  position: relative;
  z-index: 1;
  padding: 12px;
  border-radius: 30px;
  background: linear-gradient(180deg, rgba(63, 69, 81, 0.96), rgba(28, 34, 45, 0.98));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -10px 18px rgba(0, 0, 0, 0.32),
    0 10px 18px rgba(0, 0, 0, 0.18);
}

.matrix {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  width: clamp(108px, 18vw, 152px);
  user-select: none;
}

.matrix-dot {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 999px;
  border: 0;
  padding: 0;
  margin: 0;
  transition: transform 0.12s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.matrix-dot.is-off {
  background: radial-gradient(circle at 35% 35%, #7f7440 0 22%, #5b5228 50%, #2d2814 100%);
  opacity: 0.58;
  box-shadow: inset 0 1px 2px rgba(255, 247, 200, 0.12), 0 0 0 1px rgba(35, 30, 16, 0.45);
}

.matrix-dot.is-on {
  background: radial-gradient(circle at 35% 35%, #ffffff 0 20%, #e7eeff 44%, #b6c9ff 72%, #6d8dff 100%);
  opacity: 1;
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.88),
    0 0 10px rgba(174, 200, 255, 0.68),
    0 0 18px rgba(96, 123, 255, 0.26);
}

.matrix-dot:not(:disabled) {
  cursor: pointer;
}

.matrix-dot:not(:disabled):hover {
  transform: translateY(-1px) scale(1.04);
}

.matrix-dot:disabled {
  cursor: default;
}

.editor-panel {
  display: grid;
}

.editor-panel.is-hidden {
  display: none;
}

.preset-section {
  display: grid;
  gap: 10px;
  padding: 4px 0;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.15rem;
}

.section-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.preset-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(168px, 198px);
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: thin;
}

.preset-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(239, 243, 248, 0.98));
  padding: 12px;
  display: grid;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.08);
}

.preset-card:hover {
  transform: translateY(-1px);
}

.preset-card.is-active {
  border-color: #6078b6;
  box-shadow: 0 0 0 2px rgba(96, 120, 182, 0.18), 0 10px 18px rgba(17, 24, 39, 0.12);
}

.preset-card__preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.preset-card__body {
  display: grid;
  gap: 4px;
}

.preset-card__title {
  font-size: 0.98rem;
}

.preset-card__meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.preset-card--create {
  place-content: center;
  text-align: center;
  background: linear-gradient(180deg, #ffffff, #eef3f8);
}

.preset-card__plus {
  width: 46px;
  height: 46px;
  margin: 4px auto 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #dde7f3;
  color: #23415d;
  font-size: 1.5rem;
  font-weight: 700;
}

.mini-matrix {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 2px;
  padding: 6px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(38, 44, 55, 0.95), rgba(19, 24, 31, 0.95));
}

.mini-dot {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 999px;
  display: block;
}

.mini-dot.is-on {
  background: radial-gradient(circle at 35% 35%, #ffffff 0 22%, #d9e5ff 46%, #88a0ff 100%);
  box-shadow: 0 0 5px rgba(120, 151, 255, 0.42);
}

.mini-dot.is-off {
  background: radial-gradient(circle at 35% 35%, #857a41 0 22%, #463f1f 100%);
  opacity: 0.65;
}

.bottom-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  min-width: 0;
}

.panel-card {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 12px 12px 14px;
  display: grid;
  gap: 12px;
}

.panel-card legend {
  padding: 0 6px;
  font-weight: 700;
}

.field-row {
  display: grid;
  gap: 8px;
}

.field-row span {
  font-size: 0.94rem;
  font-weight: 600;
}

.text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #eef1f4;
  color: var(--text);
  font: inherit;
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-group--secondary {
  justify-content: flex-end;
}

.action-btn {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #f8fafc;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.action-btn--top {
  min-width: 74px;
}

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

.action-btn--soft {
  background: #d7dde6;
  color: #243041;
}

.action-btn--danger {
  background: #b45309;
}

.panel-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.code-block {
  position: relative;
  min-height: 210px;
  padding: 18px 16px 16px;
  border-radius: 14px;
  background: linear-gradient(180deg, #111827, #0b1220);
  color: #e7eefb;
  overflow: auto;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  cursor: pointer;
  font-size: 1.05rem;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.code-output {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.7;
  padding-top: 20px;
}

.token-variable {
  color: #7dd3fc;
}

.token-function {
  color: #fbbf24;
}

.token-number {
  color: #c4b5fd;
}

.toast-stack {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 1200;
  display: grid;
  gap: 8px;
}

.toast {
  min-width: 220px;
  max-width: 320px;
  padding: 12px 14px;
  border-radius: 12px;
  color: #f8fafc;
  box-shadow: 0 14px 24px rgba(15, 23, 42, 0.18);
}

.toast--info {
  background: #334155;
}

.toast--success {
  background: #166534;
}

.toast--warning {
  background: #b45309;
}

.toast--danger {
  background: #b91c1c;
}

.toast.is-hiding {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.46);
  padding: 20px;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: min(100%, 420px);
  border-radius: 18px;
  background: #f8fafc;
  box-shadow: 0 24px 40px rgba(15, 23, 42, 0.26);
  overflow: hidden;
}

.modal-header,
.modal-body,
.modal-footer {
  padding: 16px 18px;
}

.modal-header {
  border-bottom: 1px solid rgba(148, 163, 184, 0.3);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  color: #475569;
}

.modal-body p {
  margin: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.3);
}

#acceptConfirmBtn[data-tone='warning'] {
  background: #c2410c;
}

#alternateConfirmBtn[data-tone='warning'] {
  background: #d97706;
  color: #f8fafc;
}

#acceptConfirmBtn[data-tone='danger'] {
  background: #b91c1c;
}

@media (max-width: 768px) {
  .container {
    padding: 12px 8px 12px;
  }

  .header-content {
    padding: 25px 20px 18px;
  }

  .header-content h1 {
    font-size: 1.7em;
  }

  .subtitle {
    font-size: 1em;
  }

  .back-btn {
    top: 10px;
    left: 20px;
    min-width: 90px;
    min-height: 36px;
    font-size: 1em;
    padding: 4px 10px;
  }

  .top-panel {
    padding-top: 4px;
  }

  .sim-view {
    padding: 14px 10px;
    min-height: 250px;
  }

  .face-shell {
    gap: clamp(26px, 5vw, 52px);
    padding: 44px 42px 30px;
  }

  .matrix {
    width: clamp(96px, 26vw, 132px);
  }

  .section-heading {
    align-items: start;
  }
}

@media (max-width: 480px) {
  .header-content {
    padding: 25px 20px 12px;
  }

  .back-btn {
    top: 8px;
    font-size: 1em;
    padding: 4px 10px;
    min-width: 60px;
    min-height: 28px;
  }

  .top-panel {
    padding: 8px 4px 0;
  }

  .edit-mode-actions {
    flex-wrap: wrap;
  }

  .matrix {
    width: 86px;
    gap: 3px;
  }

  .action-row {
    justify-content: flex-end;
  }
}
