/* =============================================
   Booze Calc — style.css
   Warm whisky/amber theme, mobile-first, dark + light
   ============================================= */

:root {
  --colour-primary: #b45309;
  --colour-primary-hover: #92400e;
  --colour-primary-light: #fef3c7;
  --colour-accent: #0f766e;

  --colour-bg: #faf8f5;
  --colour-bg-secondary: #f3efe9;
  --colour-bg-tertiary: #e7e1d8;
  --colour-border: #d9d2c7;
  --colour-text: #1c1917;
  --colour-text-secondary: #57534e;
  --colour-text-tertiary: #a8a29e;
  --colour-block-bg: #ffffff;
  --colour-block-border: #e7e1d8;
  --colour-shadow: rgba(60, 40, 20, 0.08);
  --colour-error: #dc2626;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --space-xl: 1.5rem;
  --space-2xl: 2rem;

  --radius: 0.375rem;
  --radius-lg: 0.625rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --colour-primary: #f59e0b;
    --colour-primary-hover: #fbbf24;
    --colour-primary-light: #422006;
    --colour-accent: #2dd4bf;

    --colour-bg: #12100e;
    --colour-bg-secondary: #1c1917;
    --colour-bg-tertiary: #292524;
    --colour-border: #44403c;
    --colour-text: #fafaf9;
    --colour-text-secondary: #b6b0a8;
    --colour-text-tertiary: #78716c;
    --colour-block-bg: #1c1917;
    --colour-block-border: #292524;
    --colour-shadow: rgba(0, 0, 0, 0.5);
    --colour-error: #f87171;
  }
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--colour-text);
  background: var(--colour-bg);
  min-height: 100dvh;
  padding: var(--space-lg) var(--space-md) var(--space-2xl);
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--colour-primary);
  outline-offset: 2px;
}

.container {
  width: 100%;
  max-width: 44rem;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* ---------- header ---------- */

.page-head {
  & h1 {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 1.75rem;
    line-height: 1.2;
    letter-spacing: -0.01em;
  }

  & .tagline {
    color: var(--colour-text-secondary);
    font-size: 0.9375rem;
  }
}

/* ---------- panels ---------- */

.panel {
  background: var(--colour-block-bg);
  border: 1px solid var(--colour-block-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: 0 1px 2px var(--colour-shadow);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.panel-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--colour-text-secondary);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
}

.count {
  font-size: 0.8125rem;
  color: var(--colour-text-tertiary);
}

form {
  display: contents;
}

/* ---------- fields ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 0;

  & label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--colour-text-secondary);
  }

}

.field-row,
.unit-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
}

@media (min-width: 26rem) {
  /* auto-fit collapses the empty track, so a lone visible field fills the row */
  .field-row {
    grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  }

  .unit-row {
    grid-template-columns: 1fr 1fr;
  }
}

.unit-tag {
  font-weight: 400;
  color: var(--colour-text-tertiary);
}

.input {
  width: 100%;
  min-width: 0;
  padding: var(--space-sm) var(--space-md);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--colour-text);
  background: var(--colour-bg);
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  transition: border-color 0.15s ease;

  &:focus {
    outline: none;
    border-color: var(--colour-primary);
    box-shadow: 0 0 0 3px var(--colour-primary-light);
  }

  &:invalid {
    border-color: var(--colour-error);
  }

  &::placeholder {
    color: var(--colour-text-tertiary);
  }
}

.select {
  position: relative;
  display: block;

  & select {
    width: 100%;
    padding: var(--space-sm) var(--space-xl) var(--space-sm) var(--space-md);
    font-size: 1rem;
    background: var(--colour-bg);
    border: 1px solid var(--colour-border);
    border-radius: var(--radius);
    cursor: pointer;
    appearance: none;
  }

  &::after {
    content: "▾";
    position: absolute;
    right: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--colour-text-secondary);
  }
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: 0.9375rem;
  min-height: 2.75rem;

  & input {
    width: 1.125rem;
    height: 1.125rem;
    cursor: pointer;
    accent-color: var(--colour-primary);
  }
}

.hint {
  font-size: 0.8125rem;
  color: var(--colour-text-tertiary);
}

.empty {
  font-size: 0.9375rem;
  color: var(--colour-text-tertiary);
  padding: var(--space-sm) 0;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: 2.75rem;
  padding: 0.625rem var(--space-lg);
  font-size: 1rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--colour-primary);
  border-color: var(--colour-primary);
  color: #fff;

  &:hover {
    background: var(--colour-primary-hover);
    border-color: var(--colour-primary-hover);
  }
}

@media (prefers-color-scheme: dark) {
  .btn-primary {
    color: #1c1917;
  }
}

.btn-secondary {
  background: var(--colour-bg-secondary);
  border-color: var(--colour-border);
  color: var(--colour-text);

  &:hover {
    background: var(--colour-bg-tertiary);
  }
}

.btn-ghost {
  background: transparent;
  color: var(--colour-text-secondary);

  &:hover {
    background: var(--colour-bg-secondary);
    color: var(--colour-text);
  }
}

.btn-block {
  width: 100%;
}

.btn-remove {
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  font-size: 1.5rem;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  color: var(--colour-text-secondary);

  &:hover {
    border-color: var(--colour-error);
    color: var(--colour-error);
  }
}

/* ---------- mixers ---------- */

.mixers {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);

  &:empty {
    display: none;
  }
}

.mixer {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  background: var(--colour-bg-secondary);
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  padding: var(--space-md);
}

.mixer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.mixer-label {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--colour-text-secondary);
}

/* ---------- result ---------- */

.result {
  background: var(--colour-block-bg);
  border: 1px solid var(--colour-block-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: 0 1px 2px var(--colour-shadow);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.headline {
  text-align: center;
}

.headline-figure {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: var(--space-sm);
}

.big {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: clamp(2.75rem, 16vw, 4rem);
  font-weight: 700;
  line-height: 1;
  color: var(--colour-primary);
  font-variant-numeric: tabular-nums;
}

.big-unit {
  font-size: 1rem;
  font-weight: 500;
  color: var(--colour-text-secondary);
}

.headline-alt {
  margin-top: var(--space-xs);
  color: var(--colour-text-secondary);
}

.strength-bar {
  position: relative;
  height: 0.625rem;
  border-radius: 999px;
  background: var(--colour-bg-tertiary);
  overflow: hidden;
}

.strength-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--colour-accent), var(--colour-primary));
  transition: width 0.2s ease;
}

.strength-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--colour-text);
  opacity: 0.45;

  & span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-sm);
}

@media (min-width: 34rem) {
  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.stat {
  background: var(--colour-bg-secondary);
  border-radius: var(--radius);
  padding: var(--space-md);

  & dt {
    font-size: 0.75rem;
    color: var(--colour-text-secondary);
  }

  & dd {
    font-size: 1.0625rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
  }
}

.summary {
  font-size: 0.9375rem;
  color: var(--colour-text-secondary);
  text-align: center;
}

/* ---------- breakdown ---------- */

.breakdown {
  border-top: 1px solid var(--colour-border);
  padding-top: var(--space-md);

  & summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--colour-text-secondary);
    min-height: 2.25rem;

    &::-webkit-details-marker {
      display: none;
    }
  }

  & .chevron {
    transition: transform 0.15s ease;
  }

  &[open] .chevron {
    transform: rotate(180deg);
  }
}

.breakdown-body {
  overflow-x: auto;
  margin-top: var(--space-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;

  & th,
  & td {
    padding: var(--space-sm);
    text-align: left;
    border-bottom: 1px solid var(--colour-border);
    white-space: nowrap;
  }

  & th {
    font-weight: 600;
    color: var(--colour-text-secondary);
  }

  & .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  & tr:last-child td {
    border-bottom: none;
  }

  & .ingredient {
    white-space: normal;
    min-width: 8rem;
  }
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

@media (min-width: 26rem) {
  .result-actions {
    flex-direction: row;
    justify-content: center;
  }
}

.share-status {
  margin-top: calc(var(--space-sm) * -1);
  font-size: 0.8125rem;
  color: var(--colour-text-secondary);
  text-align: center;
  min-height: 1.2em;
}

/* ---------- footer ---------- */

.page-foot {
  font-size: 0.8125rem;
  color: var(--colour-text-tertiary);
  text-align: center;
  text-wrap: pretty;
}

/* ---------- dialog ---------- */

dialog {
  padding: 0;
  border: 1px solid var(--colour-border);
  border-radius: var(--radius-lg);
  background: var(--colour-block-bg);
  color: var(--colour-text);
  max-width: 24rem;
  width: calc(100% - 2rem);

  &::backdrop {
    background: rgba(0, 0, 0, 0.5);
  }
}

.dialog-inner {
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);

  & h2 {
    font-size: 1.125rem;
    font-weight: 600;
  }

  & p {
    color: var(--colour-text-secondary);
    font-size: 0.9375rem;
  }
}

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

@media (min-width: 26rem) {
  .dialog-actions {
    flex-direction: row;
    justify-content: flex-end;

    & .btn {
      min-width: 6rem;
    }
  }
}

@media (max-width: 639px) {
  dialog {
    inset: 0;
    margin: 0;
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }

  .dialog-inner {
    height: 100%;
    justify-content: center;
  }
}

@media (min-width: 40rem) {
  body {
    padding: var(--space-2xl) var(--space-lg);
  }

  .container {
    gap: var(--space-xl);
  }

  .panel,
  .result {
    padding: var(--space-xl);
  }

  .page-head h1 {
    font-size: 2rem;
  }
}
