:root {
  --bg: #f4efe4;
  --bg-deep: #e9dfcf;
  --paper: rgba(255, 252, 247, 0.9);
  --paper-strong: rgba(255, 255, 255, 0.94);
  --ink: #202420;
  --muted: #5b665d;
  --line: rgba(40, 52, 42, 0.14);
  --accent: #1f6a52;
  --accent-strong: #0f4c3a;
  --accent-soft: rgba(31, 106, 82, 0.12);
  --danger: #9f3121;
  --danger-soft: rgba(159, 49, 33, 0.1);
  --shadow: 0 22px 60px rgba(50, 44, 31, 0.12);
  --radius-xl: 28px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Noto Sans JP", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(234, 195, 123, 0.32), transparent 28%),
    radial-gradient(circle at top right, rgba(46, 124, 89, 0.22), transparent 24%),
    linear-gradient(180deg, var(--bg) 0%, #f8f4ec 42%, var(--bg-deep) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(31, 36, 31, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 36, 31, 0.035) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), transparent 86%);
}

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

button {
  cursor: pointer;
}

code,
pre {
  font-family: "Roboto Mono", monospace;
}

.page-shell {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 0 0 20px;
}

.hero {
  position: relative;
  margin-bottom: 8px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero::after {
  display: none;
}

.position-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 0;
}

.position-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 14px 4px 12px;
  border: 1px solid rgba(15, 76, 58, 0.12);
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-decoration: none;
  overflow: hidden;
  filter:
    drop-shadow(0 1px 0 rgba(15, 76, 58, 0.14))
    drop-shadow(0 -1px 0 rgba(15, 76, 58, 0.14))
    drop-shadow(1px 0 0 rgba(15, 76, 58, 0.18));
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 0 100%, 8px 50%);
  transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease, color 180ms ease;
}

.position-chip::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 15px;
  height: 100%;
  border-top: 1px solid rgba(15, 76, 58, 0.12);
  border-right: 1px solid rgba(15, 76, 58, 0.12);
  border-bottom: 1px solid rgba(15, 76, 58, 0.12);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  pointer-events: none;
}

.position-chip:first-child {
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 0 100%);
  padding-left: 10px;
}

.position-chip:first-child::after {
  width: 14px;
}

.position-chip.current {
  background: linear-gradient(135deg, #214f3f, #2d7f61);
  color: #fcfff8;
  filter:
    drop-shadow(0 1px 0 rgba(252, 255, 248, 0.16))
    drop-shadow(0 -1px 0 rgba(252, 255, 248, 0.16))
    drop-shadow(1px 0 0 rgba(252, 255, 248, 0.2));
}

.position-chip.current::after {
  border-top-color: rgba(252, 255, 248, 0.22);
  border-right-color: rgba(252, 255, 248, 0.22);
  border-bottom-color: rgba(252, 255, 248, 0.22);
}

.position-chip:hover {
  transform: translateY(-1px);
}

.hero-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  margin-top: 8px;
}

.hero-copy {
  display: grid;
  gap: 4px;
  align-content: start;
}

.hero-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.hero-logo {
  display: block;
  width: clamp(76px, 9vw, 112px);
  max-width: 22vw;
  height: auto;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.66rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.4vw, 2.2rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.hero-lead {
  margin: 0;
  max-width: 720px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.88rem;
  font-weight: 600;
}

.panel {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, var(--workspace-left, 33%)) 12px minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
  padding: 0;
}

.workflow-column,
.io-column {
  min-width: 0;
}

.workflow-column {
  display: grid;
  grid-template-columns: 1fr;
  align-content: stretch;
}

.panel {
  padding: 18px;
}

.workflow-column > .panel,
.io-column {
  border-radius: 0;
  box-shadow: none;
  border-right: 0;
}

.workflow-column > .panel {
  border-bottom: 0;
}

.workflow-column > .panel:last-child,
.io-column {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stack-panel,
.preview-panel {
  display: flex;
  flex-direction: column;
}

.preview-panel {
  min-height: 0;
}

.workspace-resizer {
  position: relative;
  cursor: col-resize;
  background:
    linear-gradient(90deg, transparent 0, transparent 5px, rgba(40, 52, 42, 0.16) 5px, rgba(40, 52, 42, 0.16) 7px, transparent 7px, transparent 100%);
}

.workspace-resizer::before {
  content: "";
  position: absolute;
  inset: 0;
}

.panel-head,
.editor-head,
.stack-summary,
.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head {
  margin-bottom: 10px;
}

.panel-head h2,
.editor-head h3 {
  margin: 0;
}

.panel-caption,
.stack-summary p,
.editor-head p,
.copy-feedback,
.field-help,
.stack-item-summary,
.error-meta,
.empty-state p {
  margin: 0;
  color: var(--muted);
}

.composer-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  flex: 1 1 auto;
}

.panel-caption,
.stack-toolbar {
  margin-bottom: 14px;
}

.stack-toolbar {
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
}

.dynamic-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.dynamic-fields[data-category="regex"] {
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field.span-2 {
  grid-column: span 2;
}

fieldset.field {
  margin: 0;
  padding: 0;
  border: 0;
}

.field-label {
  font-size: 0.92rem;
  font-weight: 700;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper-strong);
  color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

input[type="text"],
input[type="number"],
select {
  min-height: 48px;
  padding: 0 14px;
}

textarea {
  min-height: 280px;
  padding: 16px 18px;
  resize: vertical;
  line-height: 1.65;
}

#beforeText:placeholder-shown:not(:focus) {
  background: linear-gradient(180deg, rgba(250, 239, 158, 0.42), rgba(255, 252, 247, 0.96));
  animation: before-empty-pulse 1.8s ease-in-out infinite;
}

#beforeText:placeholder-shown:not(:focus)::placeholder {
  color: rgba(98, 92, 44, 0.82);
}

@keyframes before-empty-pulse {
  0%,
  100% {
    box-shadow:
      inset 0 0 0 1px rgba(231, 198, 65, 0.16),
      0 0 0 0 rgba(246, 220, 90, 0.08);
  }

  50% {
    box-shadow:
      inset 0 0 0 1px rgba(231, 198, 65, 0.34),
      0 0 0 8px rgba(246, 220, 90, 0.14);
  }
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(31, 106, 82, 0.56);
  box-shadow: 0 0 0 5px rgba(31, 106, 82, 0.12);
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper-strong);
}

.field-checkbox-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.option-checkbox {
  min-height: 0;
  align-items: flex-start;
}

.field-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.primary-button,
.ghost-button,
.chip-button {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 700;
  transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

.primary-button {
  background: linear-gradient(135deg, #214f3f, #2d7f61);
  color: #fcfff8;
  box-shadow: 0 10px 24px rgba(31, 106, 82, 0.22);
  white-space: nowrap;
}

.primary-button:hover,
.ghost-button:hover,
.chip-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.ghost-button:active,
.chip-button:active {
  transform: translateY(0);
}

.ghost-button,
.chip-button {
  border-color: rgba(40, 52, 42, 0.12);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
}

.chip-button {
  min-height: 38px;
  padding: 0 14px;
  font-size: 0.92rem;
}

.chip-button.is-active {
  background: linear-gradient(135deg, #214f3f, #2d7f61);
  border-color: transparent;
  color: #fcfff8;
}

.stack-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 14px;
  overflow: auto;
}

.stack-item {
  position: relative;
  padding: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(40, 52, 42, 0.1);
  background: var(--paper-strong);
  box-shadow: 0 8px 20px rgba(50, 44, 31, 0.06);
}

.stack-item.is-disabled {
  opacity: 0.62;
}

.stack-item.has-error {
  border-color: rgba(159, 49, 33, 0.28);
  background: linear-gradient(180deg, rgba(159, 49, 33, 0.06), rgba(255, 255, 255, 0.94));
}

.stack-item-head,
.stack-item-top,
.stack-item-actions,
.editor-grid {
  display: flex;
  gap: 12px;
}

.stack-item-head,
.stack-item-top {
  align-items: center;
  justify-content: space-between;
}

.stack-item-top {
  margin-bottom: 10px;
}

.stack-item-head {
  margin-bottom: 6px;
}

.stack-item-title {
  margin: 0;
  font-size: 1.05rem;
}

.category-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.stack-item-actions {
  flex-wrap: wrap;
  margin-top: 14px;
}

.stack-item-error {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 600;
}

.empty-state {
  padding: 28px;
  text-align: center;
  border: 1px dashed rgba(40, 52, 42, 0.18);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.4);
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1.04rem;
}

.editor-grid {
  align-items: stretch;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
}

.editor-grid > * {
  flex: 1 1 0;
  min-width: 0;
}

.preview-panel .editor-grid {
  min-height: 0;
}

.preview-panel.is-horizontal .editor-grid {
  flex-direction: row;
}

.editor-panel {
  padding: 18px;
  border: 1px solid rgba(40, 52, 42, 0.1);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.72);
  min-width: 0;
}

.editor {
  display: block;
  min-height: 320px;
  min-width: 0;
}

.readonly-editor {
  background:
    linear-gradient(180deg, rgba(31, 106, 82, 0.05), rgba(255, 255, 255, 0.96)),
    rgba(255, 255, 255, 0.96);
}

.output-display {
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.output-display.is-empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.search-hit {
  background: rgba(117, 215, 126, 0.45);
  border-radius: 4px;
  color: inherit;
  padding: 0 0.08em;
}

.copy-feedback {
  min-height: 1.4em;
  margin-top: 10px;
  font-size: 0.92rem;
}

.copy-feedback.is-success {
  color: var(--accent-strong);
}

.copy-feedback.is-error,
.error-meta {
  color: var(--danger);
}

.site-footer {
  width: 100%;
  max-width: none;
  margin: 10px auto 0;
  padding: 14px 18px;
  border-radius: 0;
  border: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.78);
  box-shadow: var(--shadow);
}

.site-footer p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  text-align: center;
}

.site-footer p + p {
  margin-top: 8px;
}

.site-footer .footer-title {
  font-size: 0.96rem;
  line-height: 1.35;
}

.site-footer strong {
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }

  .workflow-column {
    display: grid;
    grid-template-columns: 1fr;
  }

  .workflow-column > .panel {
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .workflow-column > .panel:last-child,
  .io-column {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .workspace-resizer {
    display: none;
  }

  .composer-form,
  .dynamic-fields {
    grid-template-columns: 1fr;
  }

  .composer-panel,
  .stack-panel,
  .preview-panel {
    min-height: auto;
  }

  .preview-panel.is-horizontal .editor-grid,
  .preview-panel .editor-grid {
    flex-direction: column;
  }

  .preview-panel .editor-panel {
    min-height: auto;
  }

  .preview-panel .editor {
    min-height: 220px;
  }

  .field.span-2 {
    grid-column: span 1;
  }

  .panel-head,
  .stack-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .stack-panel .panel-head,
  .preview-panel .panel-head {
    width: 100%;
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: 100%;
    padding-bottom: 24px;
  }

  .site-footer {
    width: 100%;
  }

  .hero,
  .panel {
    padding: 14px;
    border-radius: 18px;
  }

  .hero {
    padding: 8px 12px;
    border-radius: 0;
  }

  .hero-layout {
    margin-top: 6px;
  }

  .hero-title-row {
    gap: 10px;
  }

  .hero h1 {
    font-size: 1.28rem;
  }

  .hero-lead {
    font-size: 0.8rem;
  }

  .stack-item,
  .editor-panel {
    padding: 14px;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .composer-actions .primary-button,
  .editor-head .primary-button,
  .editor-head .ghost-button,
  .stack-toolbar .ghost-button,
  .preview-panel .panel-head .ghost-button {
    width: auto;
  }

  .stack-item-actions .chip-button {
    flex: 1 1 calc(50% - 8px);
  }

  .position-strip {
    gap: 6px;
  }

  .position-chip {
    min-height: 26px;
    padding: 4px 12px 4px 10px;
    font-size: 0.7rem;
  }

  .position-chip:first-child {
    padding-left: 10px;
  }

  .hero-title-row {
    align-items: flex-start;
    gap: 8px;
  }

  .hero-logo {
    width: min(92px, 28vw);
    max-width: 28vw;
  }

  .workspace {
    padding: 0;
  }

  .preview-panel .editor {
    min-height: 180px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #beforeText:placeholder-shown:not(:focus) {
    animation: none;
  }
}
