* { box-sizing: border-box; }

:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #dbe3ee;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --danger: #b91c1c;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

body.modal-open { overflow: hidden; }

button,
select,
textarea,
input {
  font: inherit;
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
.file-btn:focus-within {
  outline: 3px solid rgba(37, 99, 235, 0.28);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: #0f172a;
  color: #fff;
}

.brand-area {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
}

.help-button {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 999px;
  padding: 7px 13px;
  font-weight: 700;
}

.help-button:hover {
  background: rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

.status-area {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok { background: #16a34a; }
.badge.ng { background: #dc2626; }
.meta { font-size: 12px; opacity: 0.92; }
.topbar code {
  background: rgba(255, 255, 255, 0.14);
  padding: 1px 6px;
  border-radius: 6px;
}

.user-chip {
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.logout-form { margin: 0; }

.logout-button {
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 8px;
  padding: 6px 10px;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.logout-button:hover { background: rgba(255, 255, 255, 0.2); }

.layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 72px);
}

.panel {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

button,
.file-btn,
select {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
}

button:hover,
.file-btn:hover {
  background: #f8fafc;
  cursor: pointer;
}

.file-btn input { display: none; }
.inline-check {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 14px;
}

#sourceEditor {
  width: 100%;
  min-height: 420px;
  flex: 1;
  border: 0;
  padding: 16px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
}

.editor-footer {
  padding: 10px 16px 16px;
  color: #475569;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.text-button {
  border: 0;
  padding: 3px 0;
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
  font-size: 12px;
}

.text-button:hover {
  background: transparent;
  color: #1d4ed8;
}

.message {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 14px;
}

.message.error {
  background: #fef2f2;
  color: var(--danger);
}

.preview-host {
  margin: 12px 16px 16px;
  flex: 1;
  min-height: 420px;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 16px;
}

.empty { color: #64748b; padding-top: 32px; }
.preview-image {
  display: block;
  max-width: 100%;
  height: auto;
  background: white;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.68);
  backdrop-filter: blur(3px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(1180px, 96vw);
  max-height: 92vh;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.34);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  color: #fff;
  background: linear-gradient(135deg, #172554, #1d4ed8);
}

.modal-header h2 {
  margin: 3px 0 0;
  font-size: 24px;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.16em;
  font-weight: 800;
  opacity: 0.78;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 25px;
  line-height: 1;
}

.icon-button:hover { background: rgba(255, 255, 255, 0.22); }

.help-tabs {
  display: flex;
  gap: 5px;
  padding: 10px 16px 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  background: #f8fafc;
}

.help-tab {
  border: 0;
  border-radius: 9px 9px 0 0;
  padding: 10px 16px;
  background: transparent;
  color: #475569;
  font-weight: 700;
  white-space: nowrap;
}

.help-tab:hover { background: #eef2ff; }
.help-tab.active {
  background: #fff;
  color: #1d4ed8;
  box-shadow: inset 0 -3px 0 #2563eb;
}

.modal-body {
  padding: 22px;
  overflow: auto;
  overscroll-behavior: contain;
}

.help-panel { display: none; }
.help-panel.active { display: block; }
.help-panel h3 {
  margin: 4px 0 14px;
  font-size: 20px;
}
.help-panel h3:not(:first-child) { margin-top: 30px; }
.help-panel p { line-height: 1.75; }
.help-panel code,
.help-panel kbd {
  font-family: Consolas, "Courier New", monospace;
  background: #eef2f7;
  color: #0f172a;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.92em;
}
.help-panel kbd {
  border: 1px solid #cbd5e1;
  box-shadow: 0 1px 0 #94a3b8;
}

.step-list {
  margin: 0;
  padding-left: 26px;
  display: grid;
  gap: 14px;
}

.step-list li {
  padding-left: 5px;
  line-height: 1.65;
}

.help-callout {
  margin: 20px 0;
  padding: 15px 17px;
  border-left: 5px solid #2563eb;
  background: #eff6ff;
  border-radius: 10px;
}

.help-callout.warning {
  border-left-color: #d97706;
  background: #fffbeb;
}

.help-callout p { margin: 6px 0 0; }

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

.comparison-grid article,
.grammar-grid article,
.diagram-type-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 15px;
  background: #fff;
}

.comparison-grid h4,
.grammar-grid h4,
.diagram-type-grid h4 {
  margin: 0 0 8px;
  color: #172554;
}

.comparison-grid p,
.diagram-type-grid p {
  margin: 0 0 10px;
  line-height: 1.6;
  color: #475569;
}

.diagram-type-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 13px;
}

.syntax-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.syntax-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.syntax-table th,
.syntax-table td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.55;
}

.syntax-table th {
  background: #f1f5f9;
  color: #334155;
  font-size: 13px;
}
.syntax-table tr:last-child td { border-bottom: 0; }

.grammar-grid ul,
.rule-list {
  margin: 0;
  padding-left: 21px;
  line-height: 1.75;
}

.rule-list {
  display: grid;
  gap: 9px;
}

.examples-intro {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.examples-intro h3 { margin-bottom: 4px; }
.examples-intro p { margin: 0; color: #475569; }

.example-list {
  display: grid;
  gap: 16px;
}

.example-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

.example-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 15px;
  padding: 15px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.example-card-head h4 {
  margin: 0 0 4px;
  color: #172554;
  font-size: 17px;
}

.example-card-head p {
  margin: 0;
  color: #64748b;
  font-size: 13px;
}

.example-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.example-actions button:last-child {
  color: #fff;
  border-color: #2563eb;
  background: #2563eb;
}

.example-actions button:last-child:hover { background: #1d4ed8; }

.example-card pre {
  margin: 0;
  padding: 16px;
  max-height: 380px;
  overflow: auto;
  background: #0f172a;
  color: #dbeafe;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.example-card pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  border-radius: 0;
  font-size: inherit;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
  color: #64748b;
  font-size: 13px;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .diagram-type-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .status-area { justify-content: flex-start; }
  .layout { padding: 10px; }
  .modal { padding: 8px; }
  .modal-dialog {
    width: 100%;
    max-height: 97vh;
    border-radius: 13px;
  }
  .modal-header { padding: 15px 16px; }
  .modal-header h2 { font-size: 20px; }
  .modal-body { padding: 16px; }
  .comparison-grid,
  .grammar-grid,
  .diagram-type-grid { grid-template-columns: 1fr; }
  .example-card-head { flex-direction: column; }
  .example-actions { justify-content: flex-start; }
  .modal-footer { align-items: flex-start; }
}

/* License visibility and sources */
.license-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 5px 11px 5px 6px;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 700;
}

.license-badge:hover {
  background: rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

.license-badge.verified { border-color: rgba(134, 239, 172, 0.75); }
.license-badge.unverified { border-color: rgba(253, 186, 116, 0.85); }

.license-badge-mark {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  min-height: 25px;
  padding: 0 6px;
  border-radius: 999px;
  background: #fff;
  color: #0f172a;
  font-size: 11px;
  letter-spacing: 0.05em;
}

.license-runtime { white-space: nowrap; }

.app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 16px 18px;
  color: #475569;
  font-size: 13px;
}

.app-footer a,
.footer-link-button {
  color: #1d4ed8;
  text-decoration: none;
}

.footer-link-button {
  border: 0;
  padding: 0;
  background: transparent;
  font-size: inherit;
}

.app-footer a:hover,
.footer-link-button:hover {
  text-decoration: underline;
  background: transparent;
  cursor: pointer;
}

.license-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 18px;
}

.license-summary.verified {
  border-color: #86efac;
  background: #f0fdf4;
}

.license-summary.unverified {
  border-color: #fdba74;
  background: #fff7ed;
}

.license-emblem {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  border-radius: 18px;
  background: #0f172a;
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.license-summary h4 {
  margin: 2px 0 6px;
  font-size: 18px;
  color: #14532d;
}

.license-summary.unverified h4 { color: #9a3412; }
.license-summary p { margin: 0 0 12px; }

.license-details {
  margin: 0;
  display: grid;
  gap: 8px;
}

.license-details > div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.license-details dt {
  color: #475569;
  font-weight: 700;
}

.license-details dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.command-block,
.license-text pre {
  margin: 10px 0 16px;
  padding: 15px 16px;
  overflow: auto;
  border-radius: 12px;
  background: #0f172a;
  color: #dbeafe;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.55;
}

.command-block code {
  padding: 0;
  color: inherit;
  background: transparent;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.source-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #1e3a8a;
  text-decoration: none;
  background: #fff;
}

.source-link:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.source-link span {
  color: #64748b;
  font-size: 13px;
}

.source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.source-list a {
  display: inline-flex;
  padding: 7px 10px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  text-decoration: none;
  font-size: 13px;
}

.source-list a:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.license-text {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.license-text summary {
  padding: 13px 15px;
  font-weight: 700;
  cursor: pointer;
  background: #f8fafc;
}

.license-text pre {
  margin: 0;
  border-radius: 0;
  white-space: pre-wrap;
}

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 15%, rgba(37, 99, 235, 0.24), transparent 34%),
    radial-gradient(circle at 85% 85%, rgba(14, 165, 233, 0.18), transparent 32%),
    #0f172a;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 430px);
  padding: 34px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 28px 70px rgba(2, 6, 23, 0.45);
}

.login-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 18px;
  border-radius: 15px;
  background: #2563eb;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.login-eyebrow {
  margin: 0 0 6px;
  color: #2563eb;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.login-card h1 {
  margin: 0;
  color: #0f172a;
  font-size: 27px;
}

.login-description {
  margin: 8px 0 24px;
  color: #64748b;
}

.login-error {
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid #fecaca;
  border-radius: 10px;
  background: #fef2f2;
  color: #991b1b;
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 9px;
}

.login-form label {
  margin-top: 6px;
  color: #334155;
  font-size: 14px;
  font-weight: 700;
}

.login-form input[type="text"],
.login-form input[type="password"] {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  color: #0f172a;
}

.login-form input:focus {
  border-color: #2563eb;
  outline: 3px solid rgba(37, 99, 235, 0.18);
}

.login-form button {
  margin-top: 12px;
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: #2563eb;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.login-form button:hover { background: #1d4ed8; }

.login-note {
  margin: 18px 0 0;
  color: #64748b;
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 760px) {
  .license-summary { grid-template-columns: 1fr; }
  .license-emblem { width: 64px; height: 64px; font-size: 20px; }
  .license-details > div { grid-template-columns: 1fr; gap: 2px; }
  .source-grid { grid-template-columns: 1fr; }
  .login-card { padding: 26px 22px; }
}
