:root {
  --accent-strong: #ecd49a;
  --accent-deep: #c4a85e;
  --accent-soft: rgba(226, 200, 126, 0.14);
  --panel-width: clamp(18rem, 21vw, 24rem);
  --input-bg: rgba(20, 28, 16, 0.72);
  --input-border: rgba(226, 200, 126, 0.18);
  --panel-border: rgba(100, 114, 83, 0.55);
  --paper-shadow: 0 24px 44px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
}

body {
  height: 100vh;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--color-text);
  background:
    radial-gradient(circle at 14% -8%, rgba(226, 200, 126, 0.08), transparent 45%),
    radial-gradient(circle at 86% 8%, rgba(122, 138, 90, 0.1), transparent 32%),
    var(--color-bg);
  overflow: hidden;
}

.app-shell {
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-bottom: 1px solid var(--color-line);
  background: rgba(31, 40, 27, 0.9);
  backdrop-filter: blur(8px);
}

.title-block {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: linear-gradient(150deg, var(--color-surface-alt), var(--color-surface));
  box-shadow: var(--shadow-sm);
  animation: float-in 0.6s ease both;
}

.back-link {
  flex: 0 0 auto;
  display: inline-block;
  color: var(--color-accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.back-link:hover {
  color: var(--accent-deep);
  text-decoration: underline;
}

.title-copy {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: clamp(1.7rem, 2.8vw, 2.35rem);
  line-height: 1;
}

.header-export {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 0.8rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(56, 67, 43, 0.96), rgba(37, 46, 28, 0.94));
  box-shadow: var(--shadow-sm);
  animation: float-in 0.72s ease both;
}

.export-intro {
  display: grid;
  gap: 0.2rem;
}

.panel-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.export-intro p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.export-field {
  display: grid;
  gap: 0.4rem;
}

.export-field label,
.control label:not(.check),
.subpanel legend {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.workspace {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.workspace-inner {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr) var(--panel-width);
  grid-template-areas: "left preview right";
  gap: var(--space-sm);
  padding: var(--space-sm);
}

.controls {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--color-line) transparent;
}

.controls.left {
  grid-area: left;
}

.controls.right {
  grid-area: right;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-right: 0.35rem;
}

.panel {
  display: grid;
  gap: 0.85rem;
  padding: 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-line);
  background: linear-gradient(180deg, rgba(49, 59, 36, 0.96), rgba(31, 40, 27, 0.94));
  box-shadow: var(--shadow-sm);
  animation: float-in 0.7s ease both;
}

.panel-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-right: 1.15rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px dashed rgba(100, 114, 83, 0.7);
  cursor: pointer;
  user-select: none;
}

.panel-header::after {
  content: "▾";
  position: absolute;
  top: 0.02rem;
  right: 0;
  color: var(--color-accent);
  font-size: 0.86rem;
  transition: transform 0.18s ease;
}

.panel-header h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: 1.12rem;
  line-height: 1.05;
}

.panel-header p {
  margin: 0;
  text-align: right;
  color: var(--color-text-muted);
  font-size: 0.78rem;
  line-height: 1.3;
}

.panel-header:focus-visible,
input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.panel.is-collapsed > :not(.panel-header) {
  display: none;
}

.panel.is-collapsed .panel-header {
  padding-bottom: 0;
  border-bottom: none;
}

.panel.is-collapsed .panel-header::after {
  transform: rotate(-90deg);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem 0.7rem;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
  font-size: 0.94rem;
}

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

.control-heading label {
  margin: 0;
}

.control-action.btn.btn-compact {
  min-height: 1.9rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

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

.control-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.control-row.preset-row select {
  flex: 1 1 auto;
  min-width: 0;
}

.control-row.slider-row {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) 4.5rem 2rem;
  align-items: center;
  gap: 0.55rem;
}

.control-row.slider-row input[type="range"] {
  grid-column: 2;
}

.control-row.slider-row output {
  grid-column: 3;
}

input,
select,
output {
  width: 100%;
  min-width: 0;
  border-radius: 0.7rem;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--color-text);
  font: inherit;
}

#coords-index-start,
#coords-index-start option {
  font-family: "Source Sans 3", "Segoe UI Symbol", "Noto Sans Symbols 2", sans-serif;
}

input,
select {
  height: 2.65rem;
  padding: 0 0.85rem;
}

input[type="number"],
input[type="text"],
select {
  appearance: none;
}

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--color-accent) 50%),
    linear-gradient(135deg, var(--color-accent) 50%, transparent 50%);
  background-position:
    calc(100% - 1.1rem) calc(50% - 0.15rem),
    calc(100% - 0.75rem) calc(50% - 0.15rem);
  background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
  background-repeat: no-repeat;
  padding-right: 2.1rem;
}

input::placeholder {
  color: rgba(244, 240, 230, 0.55);
}

input:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input[type="color"] {
  padding: 0.22rem;
  height: 2.65rem;
}

input[type="range"] {
  appearance: none;
  height: 0.5rem;
  padding: 0;
  background: linear-gradient(90deg, rgba(226, 200, 126, 0.42), rgba(226, 200, 126, 0.08));
  border: 1px solid rgba(226, 200, 126, 0.15);
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid rgba(31, 40, 27, 0.75);
  background: var(--color-accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid rgba(31, 40, 27, 0.75);
  background: var(--color-accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

input[type="range"]::-moz-range-track {
  height: 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(226, 200, 126, 0.15);
  background: linear-gradient(90deg, rgba(226, 200, 126, 0.42), rgba(226, 200, 126, 0.08));
}

output {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.1rem;
  padding: 0 0.6rem;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.font-select {
  font-size: 0.95rem;
}

label.check {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 2.65rem;
  padding: 0.72rem 0.85rem;
  border-radius: 0.7rem;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--color-text);
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
}

label.check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--color-accent);
}

label.check span {
  font-size: 0.9rem;
}

.hint {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.subpanel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.subpanel {
  margin: 0;
  padding: 0.95rem;
  border: 1px solid rgba(100, 114, 83, 0.72);
  border-radius: 0.9rem;
  background: rgba(20, 28, 16, 0.48);
}

fieldset {
  min-width: 0;
  border: none;
  margin: 0;
  padding: 0;
}

fieldset:disabled {
  opacity: 0.55;
}

.subpanel legend {
  padding: 0 0.35rem;
}

.btn,
.stepper-btn {
  position: relative;
  border: 1px solid var(--color-line);
  border-radius: 0.7rem;
  background: var(--color-surface-alt);
  color: var(--color-text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.65rem;
  padding: 0.7rem 1rem;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.btn:hover,
.stepper-btn:hover {
  transform: translateY(-1px);
  background: rgba(226, 200, 126, 0.1);
}

.btn.primary {
  border-color: rgba(226, 200, 126, 0.7);
  background: linear-gradient(145deg, var(--color-accent), #c4a85e);
  color: var(--color-bg);
}

.btn.primary:hover {
  background: linear-gradient(145deg, #ecd49a, #c4a85e);
}

.btn.btn-compact {
  min-height: 2.2rem;
  padding: 0.5rem 0.85rem;
  font-size: 0.82rem;
}

.stepper-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  justify-self: center;
  box-shadow: none;
}

.stepper-btn:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.export-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.export-share {
  display: flex;
}

.export-share .btn {
  width: 100%;
}

.header-action {
  min-width: 8rem;
}

.a4-zone {
  grid-area: preview;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.workspace-panel {
  background: transparent;
}

.workspace-card {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}

.a4-wrapper {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0.25rem, 0.8vw, 0.6rem);
  border-radius: calc(var(--radius-md) - 0.1rem);
  border: 1px dashed rgba(226, 200, 126, 0.22);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0)),
    rgba(20, 28, 16, 0.42);
  overflow: hidden;
  overscroll-behavior: contain;
  user-select: none;
}

.a4-paper {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: #ffffff;
  border: 1px solid rgba(24, 24, 24, 0.18);
  box-shadow: var(--paper-shadow);
  transform-origin: center center;
  will-change: transform;
  transition: transform 0.08s ease-out;
}

.a4-wrapper.is-zoomed {
  cursor: grab;
}

.a4-wrapper.is-dragging {
  cursor: grabbing;
}

.a4-paper[data-orientation="portrait"] {
  aspect-ratio: 210 / 297;
}

.a4-paper[data-orientation="landscape"] {
  aspect-ratio: 297 / 210;
}

#hex-canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

.filename {
  width: 100%;
}

.export-modal[hidden] {
  display: none !important;
}

.export-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.export-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 8, 0.72);
  backdrop-filter: blur(10px);
}

.export-modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 42rem);
  display: grid;
  gap: 1rem;
  padding: 1.2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(49, 59, 36, 0.98), rgba(31, 40, 27, 0.96));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.export-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.export-modal-head h2 {
  margin: 0.2rem 0 0;
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: clamp(1.35rem, 2.2vw, 1.8rem);
}

.modal-close {
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 auto;
  border: 1px solid var(--color-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text);
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: rgba(226, 200, 126, 0.1);
}

.layout-overflow {
  outline: 2px solid #d45a5a;
  outline-offset: 2px;
}

.is-hidden {
  display: none !important;
}

::-webkit-scrollbar {
  width: 0.4rem;
  height: 0.4rem;
}

::-webkit-scrollbar-track {
  background: var(--color-olive-deep);
}

::-webkit-scrollbar-thumb {
  background: var(--color-line);
  border-radius: 999px;
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1500px) {
  :root {
    --panel-width: clamp(16rem, 20vw, 21rem);
  }

  .panel {
    padding: 1rem;
  }

  .control-grid {
    gap: 0.7rem 0.6rem;
  }
}

@media (max-width: 1280px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    grid-template-rows: auto auto;
  }

  .workspace {
    height: auto;
    overflow: visible;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .workspace-inner {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "preview"
      "left"
      "right";
  }

  .controls {
    overflow: visible;
  }

  .a4-zone {
    min-height: clamp(24rem, 70vw, 42rem);
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 0.75rem;
  }

  .title-block,
  .workspace-card,
  .panel {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }

  .workspace-card {
    padding-top: 0;
    padding-bottom: 0;
  }

  .export-actions,
  .subpanel-grid,
  .control-grid {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .panel-header {
    gap: 0.5rem;
  }

  .panel-header p {
    display: none;
  }

  .control-row.slider-row {
    grid-template-columns: 2rem minmax(0, 1fr) 4rem 2rem;
  }

  .topbar-actions {
    width: 100%;
    margin-right: 0;
  }

  .header-action {
    width: 100%;
  }

  .export-modal {
    padding: 0.75rem;
  }

  .export-modal-panel {
    padding: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
