:root {
  color-scheme: dark;
  --bg: #151311;
  --panel: #1b1d1d;
  --panel-warm: #2a221c;
  --line: rgba(198, 151, 86, 0.28);
  --line-strong: #72583c;
  --text: #f4eadc;
  --muted: #b7aa99;
  --accent: #d69a45;
  --accent-bright: #f2c36d;
  --section-title-color: #ffd27a;
  --steel: #87aab5;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --workspace-panel-height: clamp(360px, 44vh, 440px);
}

* {
  box-sizing: border-box;
}

::selection {
  color: #1a1a1a;
  background: #ffd27a;
  text-shadow: none;
}

::-moz-selection {
  color: #1a1a1a;
  background: #ffd27a;
  text-shadow: none;
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(214, 154, 69, 0.07), transparent 22%, rgba(135, 170, 181, 0.05) 54%, transparent 78%),
    repeating-linear-gradient(8deg, rgba(255, 210, 150, 0.035) 0 2px, transparent 2px 18px),
    linear-gradient(135deg, #17130f 0%, #101515 52%, #251a12 100%);
  background-size: 28px 28px, 28px 28px, auto, auto, auto;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 18px;
  width: 100%;
  min-height: 100vh;
  min-width: 0;
  padding: 22px;
  overflow-x: auto;
}

.title-bar,
.project-panel,
.input-panel,
.ring-panel,
.preview-panel,
.values-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(42, 34, 28, 0.96), rgba(27, 29, 29, 0.96));
  box-shadow: var(--shadow);
}

.title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 82px;
  padding: 12px 20px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
}

.app-logo {
  display: block;
  height: 86px !important;
  width: auto !important;
  max-height: 86px !important;
  max-width: 320px !important;
  object-fit: contain;
  margin-right: 14px;
  flex-shrink: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 750;
}

h2 {
  font-size: 18px;
  font-weight: 700;
}

.project-panel h2,
.input-panel h2,
.ring-panel h2,
.preview-panel h2,
.values-panel h2 {
  color: var(--section-title-color);
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--accent-bright);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-pill,
.dimension-badge {
  border: 1px solid rgba(135, 170, 181, 0.45);
  border-radius: 6px;
  padding: 8px 10px;
  color: #d9f0f6;
  background: rgba(135, 170, 181, 0.12);
  font-size: 13px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(250px, 280px) minmax(360px, 1fr);
  gap: 18px;
  min-height: 0;
  min-width: 0;
  align-items: start;
}

.project-panel {
  display: grid;
  overflow: hidden;
}

.project-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(0, 2fr);
  gap: 10px;
  align-items: end;
  min-width: 0;
  padding: 12px 18px 14px;
}

.input-panel {
  display: flex;
  flex-direction: column;
  align-self: start;
  gap: 10px;
  height: var(--workspace-panel-height);
  max-height: var(--workspace-panel-height);
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 14px 16px;
}

.input-title {
  flex: 0 0 auto;
}

.inputs-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.field {
  display: grid;
  gap: 5px;
  line-height: 1.15;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.inline-help-button {
  display: inline-grid;
  place-items: center;
  width: 18px;
  min-width: 18px;
  height: 18px;
  border-color: var(--line-strong);
  border-radius: 50%;
  padding: 0;
  color: #20150b;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  vertical-align: middle;
}

input,
select,
button {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  background: #101414;
  font: inherit;
  line-height: 1.15;
  outline: none;
  min-width: 0;
}

button {
  width: auto;
  min-width: 120px;
  cursor: pointer;
  color: #20150b;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  font-size: 13px;
  font-weight: 800;
}

button:hover {
  border-color: var(--accent-bright);
  filter: brightness(1.06);
}

.danger-button {
  color: #ffe9e6;
  background: linear-gradient(180deg, #9f3f35, #6e2b26);
}

input:focus,
select:focus,
button:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(214, 154, 69, 0.18);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 0;
}

.save-project-help {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.export-project-help {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.import-project-help {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.save-project-help-popup {
  position: fixed;
  z-index: 1000;
  width: fit-content;
  max-width: min(420px, calc(100vw - 32px));
  max-height: 220px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.export-project-help-popup {
  position: fixed;
  z-index: 1000;
  width: fit-content;
  max-width: min(460px, calc(100vw - 32px));
  max-height: 240px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.import-project-help-popup {
  position: fixed;
  z-index: 1000;
  width: fit-content;
  max-width: min(420px, calc(100vw - 32px));
  max-height: 200px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.hidden-file-input {
  display: none;
}

.ring-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  align-self: start;
  gap: 10px;
  height: var(--workspace-panel-height);
  max-height: var(--workspace-panel-height);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 14px 16px;
}

.ring-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.title-with-help {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.help-button {
  display: grid;
  place-items: center;
  width: 24px;
  min-width: 24px;
  height: 24px;
  border-color: var(--line-strong);
  border-radius: 50%;
  padding: 0;
  color: #20150b;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  font-weight: 800;
}

.help-popup {
  position: absolute;
  z-index: 5;
  top: calc(100% + 8px);
  left: 0;
  display: none;
  width: 220px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--text);
  background: linear-gradient(145deg, rgba(42, 34, 28, 0.98), rgba(16, 20, 20, 0.98));
  box-shadow: var(--shadow);
  line-height: 1.25;
}

.help-popup.save-project-help-popup {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
}

.help-popup.export-project-help-popup {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
}

.help-popup.import-project-help-popup {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
}

.help-popup-wide {
  width: 460px;
  max-width: min(500px, calc(100vw - 48px));
  max-height: 250px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px;
  line-height: 1.4;
  white-space: normal;
}

.inputs-help-popup {
  width: 250px;
  max-width: calc(100vw - 48px);
  max-height: 180px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  line-height: 1.35;
  white-space: pre-line;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.tutorial-help-popup {
  position: fixed;
  width: 260px;
}

.tutorial-help-popup.calculated-help-popup {
  z-index: 1000;
  width: 360px;
  max-width: min(420px, calc(100vw - 32px));
  max-height: 240px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  line-height: 1.35;
  white-space: normal;
}

.help-popup.is-open {
  display: block;
}

.ring-panel-heading .dimension-badge {
  flex: 0 0 auto;
  min-width: 104px;
  padding: 6px 9px;
}

.ring-actions button {
  min-width: 0;
  flex: 1 1 0;
  padding: 0 6px;
}

.ring-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  max-height: 322px;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 4px;
}

.ring-list-item {
  display: grid;
  gap: 3px;
  width: 100%;
  height: auto;
  min-height: 58px;
  padding: 9px 10px;
  color: var(--text);
  text-align: left;
  background: rgba(16, 20, 20, 0.74);
}

.ring-list-item.is-selected {
  border-color: var(--accent);
  background: rgba(214, 154, 69, 0.16);
}

.ring-list-title {
  font-weight: 800;
}

.ring-list-detail {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  align-self: start;
  height: var(--workspace-panel-height);
  max-height: var(--workspace-panel-height);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
}

.preview-stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 20px;
  background:
    linear-gradient(90deg, rgba(135, 170, 181, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(135, 170, 181, 0.08) 1px, transparent 1px),
    #101414;
  background-size: 24px 24px;
}

#ringSvg {
  width: 100%;
  height: 100%;
  max-width: min(100%, 620px);
  max-height: 100%;
  aspect-ratio: 1;
  filter: drop-shadow(0 20px 24px rgba(0, 0, 0, 0.45));
}

.ring-segment {
  stroke: rgba(247, 212, 151, 0.54);
  stroke-width: 1;
}

.ring-segment:nth-child(odd) {
  fill: #8f5628;
}

.ring-segment:nth-child(even) {
  fill: #b57534;
}

.center-hole {
  fill: #101414;
  stroke: rgba(135, 170, 181, 0.46);
  stroke-width: 2;
}

.center-lines {
  stroke: rgba(135, 170, 181, 0.28);
  stroke-width: 1;
}

.values-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px 20px 14px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  min-width: 0;
  margin: 0;
}

.result {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(16, 20, 20, 0.74);
  line-height: 1.15;
}

.result dt {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.15;
}

.result dd {
  margin: 4px 0 0;
  color: var(--accent-bright);
  font-size: 23px;
  font-weight: 800;
  line-height: 1.05;
}

.invalid-note {
  fill: #e8796f;
  font-size: 14px;
  font-weight: 700;
  text-anchor: middle;
}

.print-project-view {
  display: none;
}

.confirmation-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(10, 9, 8, 0.72);
}

.confirmation-modal.is-open {
  display: grid;
}

.confirmation-card {
  width: min(420px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--text);
  background: linear-gradient(145deg, rgba(42, 34, 28, 0.98), rgba(16, 20, 20, 0.98));
  box-shadow: var(--shadow);
}

.confirmation-card h2 {
  color: var(--section-title-color);
}

.confirmation-card p {
  margin-top: 12px;
  line-height: 1.35;
  white-space: pre-line;
}

.confirmation-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 1050px) {
  .app-shell {
    padding: 16px;
  }

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

  .project-controls .field {
    grid-column: 1 / -1;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .input-panel,
  .ring-panel,
  .preview-panel {
    width: 100%;
  }

  .preview-panel {
    min-height: 340px;
  }
}

@media (max-width: 700px) {
  .inputs-body {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    min-width: 0;
    color: #111;
    background: #fff;
    font-family: "Segoe UI", Arial, sans-serif;
  }

  .app-shell,
  .confirmation-modal,
  .help-popup,
  .tutorial-help-popup {
    display: none !important;
  }

  .print-project-view {
    display: block;
    padding: 24px;
  }

  .print-project-view h1 {
    margin: 0 0 8px;
    color: #111;
    font-size: 24px;
  }

  .print-heading {
    margin-bottom: 18px;
  }

  .print-heading p {
    color: #333;
  }

  .print-project-view table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
  }

  .print-project-view th,
  .print-project-view td {
    border: 1px solid #888;
    padding: 6px 7px;
    text-align: left;
    vertical-align: top;
  }

  .print-project-view th {
    background: #eee;
    font-weight: 700;
  }
}

body::before {
  content: "CSS VERSION TEST 4";
  position: fixed;
  top: 0;
  right: 0;
  background: red;
  color: white;
  padding: 8px 12px;
  z-index: 99999;
  font-weight: bold;
}
