:root {
  --bg-top: #172330;
  --bg-bottom: #0f171f;
  --shell: #151f29;
  --display: #0c1218;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 201, 78, 0.28);
  --text-main: #f3efdf;
  --text-soft: #a8b5bf;
  --accent: #ffc94e;
  --accent-strong: #ff9c33;
  --key: #1b2733;
  --key-soft: #223241;
  --shadow: 0 18px 40px rgba(3, 8, 12, 0.45);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text-main);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: 18px;
}

.calculator-shell {
  width: min(100%, 440px);
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(29, 43, 56, 0.96), rgba(15, 23, 31, 0.98));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.brand-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  position: relative;
}

.brand-mark,
.display-label {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--text-soft);
}

h1 {
  margin: 6px 0 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.menu-wrap {
  position: relative;
  flex: 0 0 auto;
}

.menu-toggle {
  width: 48px;
  min-width: 48px;
  min-height: 44px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 5px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.menu-toggle[aria-expanded="true"] {
  border-color: var(--line-strong);
  background: rgba(255, 201, 78, 0.1);
}

.menu-toggle-line {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--text-main);
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 5;
  min-width: 168px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(15, 23, 31, 0.98);
  box-shadow: 0 18px 28px rgba(3, 8, 12, 0.4);
}

.menu-dropdown[hidden] {
  display: none;
}

.menu-item {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.menu-item.is-active {
  border-color: var(--line-strong);
  background: rgba(255, 201, 78, 0.14);
  color: #ffe6a5;
}

.menu-item.install-link {
  border-color: rgba(255, 201, 78, 0.22);
  background: rgba(255, 201, 78, 0.08);
  color: #ffe6a5;
}

.menu-item.install-link.is-ready {
  background: rgba(255, 201, 78, 0.16);
  border-color: rgba(255, 201, 78, 0.4);
}

.menu-panel {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(12, 18, 24, 0.68);
}

.menu-panel[hidden] {
  display: none;
}

.menu-section[hidden] {
  display: none;
}

.help-panel {
  display: grid;
  gap: 12px;
}

.help-card {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
}

.help-kicker {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
}

.help-title {
  margin: 6px 0 0;
  font-size: 1rem;
  line-height: 1.3;
}

.help-text {
  margin: 10px 0 0;
  color: var(--text-soft);
  font-size: 0.88rem;
  line-height: 1.45;
}

.help-steps {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--text-soft);
  font-size: 0.84rem;
  line-height: 1.5;
}

.help-steps li + li {
  margin-top: 6px;
}

.help-diagram {
  margin: 0;
}

.help-svg {
  width: 100%;
  height: auto;
  display: block;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.015)),
    rgba(12, 18, 24, 0.78);
}

.help-line,
.help-angle-box {
  fill: none;
  stroke: rgba(243, 239, 223, 0.86);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.help-base-line,
.help-height-line,
.help-height-guide {
  stroke: var(--accent);
}

.help-height-guide {
  stroke-dasharray: 7 7;
}

.help-accent-line {
  stroke: #ffe6a5;
}

.help-fill {
  fill: rgba(255, 201, 78, 0.14);
  stroke: rgba(255, 201, 78, 0.22);
  stroke-width: 2;
}

.help-tag-bg {
  fill: rgba(15, 23, 31, 0.92);
  stroke: rgba(255, 201, 78, 0.28);
  stroke-width: 1.5;
}

.help-arrow-line {
  stroke: rgba(255, 201, 78, 0.58);
  stroke-width: 2;
  stroke-linecap: round;
}

.help-svg-label {
  fill: var(--text-main);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 14px;
  font-weight: 700;
}

.help-svg-tag-text {
  fill: #ffe6a5;
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-anchor: middle;
}

.rise-run-panel,
.triangle-panel {
  display: grid;
  gap: 12px;
}

.rise-run-fields,
.triangle-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rise-run-field,
.triangle-field {
  min-height: 72px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
}

.rise-run-field-wide {
  grid-column: 1 / -1;
}

.rise-run-field.is-active,
.triangle-field.is-active {
  border-color: var(--line-strong);
  background: rgba(255, 201, 78, 0.12);
}

.rise-run-label,
.rise-run-card-label,
.triangle-label,
.triangle-card-label {
  display: block;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--text-soft);
}

.rise-run-value,
.triangle-value {
  display: block;
  margin-top: 8px;
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rise-run-results,
.triangle-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rise-run-card,
.triangle-card {
  min-height: 74px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
}

.rise-run-card-value,
.triangle-card-value {
  display: block;
  margin-top: 8px;
  font-size: 1.05rem;
  font-weight: 700;
}

.rise-run-note,
.triangle-note {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.88rem;
  line-height: 1.4;
}

.rise-run-note.is-empty,
.triangle-note.is-empty {
  display: none;
}

.rise-run-note.error,
.triangle-note.error {
  color: #ffb8ad;
}

.display-panel {
  width: 100%;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--display);
  overflow: hidden;
}

.display-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 108px;
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  box-shadow: inset 0 0 0 1px rgba(255, 201, 78, 0.04);
  overflow: hidden;
}

.display-panel.is-tool-mode .tab-row {
  display: none;
}

.display-panel.is-tool-mode .display-bar {
  margin-top: 0;
}

.expression-display {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
  scrollbar-width: none;
}

.expression-display::-webkit-scrollbar {
  display: none;
}

.expression-display {
  font-size: clamp(2rem, 8vw, 3.2rem);
  line-height: 1.08;
  color: var(--text-main);
  min-height: 3.5rem;
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tab-button {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-button.is-active {
  border-color: var(--line-strong);
  background: rgba(255, 201, 78, 0.14);
  color: #ffe6a5;
}

.status-message {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-soft);
  font-size: 0.88rem;
  line-height: 1.45;
}

.status-message.is-empty {
  display: none;
}

.status-message.error {
  color: #ffb8ad;
}

code {
  padding: 0.12em 0.34em;
  border-radius: 0.45em;
  background: rgba(255, 201, 78, 0.12);
  color: #ffe6a5;
}

.history-panel {
  margin-top: 0;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-caption {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-soft);
}

.history-clear {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-soft);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.history-clear:disabled {
  opacity: 0.45;
  cursor: default;
}

.history-list {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.history-list::-webkit-scrollbar {
  display: none;
}

.history-empty {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.84rem;
}

.history-chip {
  flex: 0 0 auto;
  min-width: 148px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
}

.history-expression,
.history-result {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-expression {
  color: var(--text-soft);
  font-size: 0.75rem;
}

.history-result {
  margin-top: 4px;
  font-size: 0.96rem;
  font-weight: 700;
}

.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.shortcut-button {
  min-height: 42px;
  border: 1px solid rgba(255, 201, 78, 0.16);
  border-radius: 999px;
  background: rgba(255, 201, 78, 0.08);
  color: #ffe6a5;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.key-button {
  min-height: 66px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--key);
  color: var(--text-main);
  font-size: 1.12rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.key-button:hover {
  transform: translateY(-1px);
}

.key-button:active {
  transform: translateY(1px);
}

.key-button.operator {
  background: rgba(255, 156, 51, 0.2);
}

.key-button.helper,
.key-button.utility {
  background: var(--key-soft);
}

.key-button.solve {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #241606;
  box-shadow: 0 10px 22px rgba(255, 156, 51, 0.24);
}

body.is-help-view .display-panel,
body.is-help-view .shortcut-grid,
body.is-help-view .keypad-grid {
  display: none !important;
}

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

  .calculator-shell {
    padding: 16px;
  }

  .key-button {
    min-height: 60px;
  }

  .shortcut-button {
    min-height: 40px;
  }

  .menu-dropdown {
    min-width: 156px;
  }
}
