/*
  File: style.css
  Purpose: Responsive styling for EMC OK! homepage and Unit Calculator
  Author: Erwin Tielemans
  Updated: 2025-12-12
  Version: 2.2 (1366×768 floor, container-driven scaling)
*/

/* ============================= */
/* Tokens and base               */
/* ============================= */
:root{
  /* spacing */
  --pad: clamp(0.75rem, 1.2vw, 2rem);
  --gap: clamp(0.4rem, 1vw, 1rem);

  /* typography */
  --fs-body: clamp(14px, 1.1vw + 0.2rem, 17px);
  --fs-h1: clamp(1.4rem, 2.8vw, 2.2rem);
  --fs-h2: clamp(0.9rem, 1.6vw, 1.1rem);
  --fs-h3: clamp(0.85rem, 1.2vw, 1rem);
  --fs-label: clamp(1rem, 1.6vw, 1.3rem);
  --fs-key: clamp(0.9rem, 1.6vw, 1.25rem);

  /* CORRECTION 1: slightly smaller display font */
  --fs-display: clamp(0.95rem, 1.6vw, 1.25rem);

  /* layout bounds */
  --maxw-calculator: clamp(360px, 82vw, 1400px); /* allow growth on larger screens */

  /* colors */
  --brand-orange: #ff8c00;
  --bg-0: #121212;
  --bg-1: #1e1e1e;
  --text-0: #ffffff;
  --text-1: #ccc;
  --text-2: #888;

  /* misc */
  --radius: 12px;
  --border: 1px solid #444;
}

html{ font-size: var(--fs-body); }
*{ box-sizing: border-box; }
img, svg, canvas, video{ max-width: 100%; height: auto; }

body{
  margin: 0;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-0);
  color: var(--text-0);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: auto;          /* avoid 100vh traps */
  -webkit-text-size-adjust: 100%;
}
@supports (height: 1svh){
  body{ min-height: 100svh; } /* small viewport units when available */
}

/* ============================= */
/* Header                        */
/* ============================= */
header{
  padding: calc(var(--pad) * 0.75) var(--pad) calc(var(--pad) * 0.5);
  text-align: center;
}
header h1{
  font-size: var(--fs-h1);
  margin: .25rem 0;
  background: linear-gradient(135deg, #f0f0f0, #888, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
header h2{ font-weight: 300; font-size: var(--fs-h2); color: var(--text-1); margin-top: .25rem; }
header h3{ font-weight: 300; font-size: var(--fs-h3); color: var(--text-1); margin-top: 0; }

/* ============================= */
/* Footer                        */
/* ============================= */
.site-footer{
  background-color: var(--bg-0);
  color: #f0f0f0;
  padding: calc(var(--pad) * 0.6);
  text-align: center;
  border-top: 2px solid var(--brand-orange);
  font-family: Arial, sans-serif;
}
.site-footer a.github-link{ color: var(--brand-orange); text-decoration: none; }
.site-footer a.github-link:hover{ text-decoration: underline; }
.donate-button{
  background-color: var(--brand-orange);
  color: #1e1e1e;
  border: none;
  padding: .5rem 1rem;
  border-radius: .5rem;
  cursor: pointer;
  font-weight: bold;
  transition: background-color .2s ease;
}
.donate-button:hover{ background-color: #e07b00; }

/* ============================= */
/* Utility tags                  */
/* ============================= */
.grey-rounded{ background-color: rgba(128,128,128,.3); padding: 10px; border-radius: 10px; }
.yellow-rounded{ background-color: rgba(224,231,29,.3); padding: 10px; border-radius: 10px; }
.blinking{ animation: blinker 1s linear infinite; }
@keyframes blinker{ 50%{ opacity: 0; } }

/* ============================= */
/* Calculator card               */
/* ============================= */
.calculator{
  background: var(--bg-1);
  border-radius: var(--radius);
  padding: var(--pad);
  max-width: var(--maxw-calculator);
  width: 100%;
  box-shadow: 0 0 20px rgba(0,0,0,.5);
  border: 2px solid grey;
  container-type: inline-size;           /* enable container queries and cqw units */

  /* CORRECTION 2+3: key size & gap ~15% smaller */
  --key-size: clamp(40px, 6.8cqw, 88px);  /* floor for tight laptops, cap on 4K */
  --key-gap:  clamp(6px, 0.85cqw, 12px);
}

/* ============================= */
/* Display                       */
/* ============================= */
.display{
  background: linear-gradient(to top, #222, #2e2e2e);
  border: var(--border);
  border-radius: 8px;
  padding: calc(var(--pad) * 0.6);
  font-size: var(--fs-display);
  margin-bottom: var(--gap);
  color: #0f0;
  font-family: 'Courier New', Courier, monospace;
  box-shadow: inset 0 1px 3px rgba(0,255,0,.2);
  word-break: break-all;
  min-height: 2rem;
  max-height: 22vh;                        /* keeps keypad in view on 1366×768 */
  overflow: auto;
}

/* ============================= */
/* Labels                        */
/* ============================= */
.label{
  font-size: var(--fs-label);
  color: #aaa;
  margin: clamp(0.4rem, 1vw, 0.9rem) 0;
}
.section-label,
.spacer{
  margin: clamp(0.7rem, 1.2vw, 1.4rem) 0;
  font-weight: 500;
  font-size: 1rem;
  text-align: center;
}
.subtitle{ font-size: .85rem; color: var(--text-2); margin-top: .25rem; text-align: center; }

/* ============================= */
/* Keypad and buttons            */
/* ============================= */
.keypad{
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  grid-auto-rows: var(--key-size);        /* fixed row height per key size */
  gap: var(--key-gap);
  margin-top: var(--key-gap);
}
.keypad button,
.convert-section button,
.final-buttons button{
  width: 100%;
  height: 100%;                           /* the grid controls height */
  padding: 0;                             
  min-height: 0;                           /* allow grid sizing */
  font-size: var(--fs-key);
  background: linear-gradient(to bottom, #2c2c2c, #1c1c1c);
  color: #fff;
  border: var(--border);
  border-radius: 8px;
  box-shadow: inset 0 -2px 4px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease, background-color .2s ease;
}
.keypad button:active,
.convert-section button:active,
.final-buttons button:active{
  box-shadow: inset 0 2px 2px rgba(0,0,0,.6);
  transform: translateY(1px);
}
.keypad .blue{ background: linear-gradient(to bottom, #007aff, #005fcc); border-color: #0047aa; }
.keypad .orange{ background: linear-gradient(to bottom, #ff9500, #cc7a00); border-color: #b96b00; }
.keypad .wide{ grid-column: span 2; }

/* ============================= */
/* Conversion action grids       */
/* ============================= */
.convert-section,
.final-buttons{
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: var(--key-gap);
  margin-top: var(--key-gap);
}
.convert-section button,
.final-buttons button{
  /* not square keys, compact controls */
  height: auto;
  min-height: clamp(40px, 5cqw, 56px);
  padding: clamp(10px, 0.8cqw, 14px);
  font-size: clamp(0.9rem, 1.2cqw, 1.1rem);
}

/* ============================= */
/* Unit buttons                  */
/* ============================= */
.unit-button{
  background-color: #666;
  color: #eee;
  border: 1px solid #444;
  border-radius: 8px;
  font-weight: 500;
  transition: background-color .2s ease;
  padding: clamp(0.5rem, 0.8vw, 0.9rem);
  white-space: normal; /* allow wrap on narrow widths */
  text-align: center;
}
.unit-button:hover{ background-color: #888; }
.unit-button.selected{ border: 2px solid #f90; background-color: #a96d00; color: #fff; }

/* Special units: λ, λ/4, f */
.unit-button.special-unit{
  background-color: #666;
  color: var(--brand-orange);
  border: 1px solid #444;
  font-weight: 500;
}
.unit-button.special-unit:hover{ background-color: #357abd; }
.unit-button.special-unit.selected{
  border: 2px solid #f90;      /* same highlight border */
  background-color: #a96d00;   /* same selected background */
  color: var(--brand-orange);  /* keep orange text */
}


/* D/S toggle */
#toggleDS{
  background: linear-gradient(to bottom, #007aff, #005fcc);
  color: #fff; font-weight: 500;
  padding: clamp(0.5rem, 0.8vw, 0.9rem);
  font-size: var(--fs-key);
  border: 1px solid #0047aa;
  border-radius: 8px;
  box-shadow: inset 0 -2px 4px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
  cursor: pointer;
  transition: background-color .2s ease;

  /* proper centering */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1;
  white-space: nowrap;
}
#toggleDS:hover{ background: linear-gradient(to bottom, #339dff, #007aff); }

/* ============================= */
/* Conversion sections layout    */
/* ============================= */
.conversion-sections{
  display: flex;
  flex-direction: row;
  gap: var(--gap);
  justify-content: space-between;
  margin-top: calc(var(--gap) * 2);
  flex-wrap: wrap;
}
.conversion-panel{
  flex: 1 1 45%;
  padding: calc(var(--pad) * 0.6);
}

/* ============================= */
/* Narrow viewports              */
/* ============================= */
@media (max-width: 768px){
  .conversion-sections{ flex-direction: column; }
  .conversion-panel{ width: 100%; }

  /* FORCE 4 COLUMNS EVEN ON MOBILE */
  .convert-section{
    grid-template-columns: repeat(4, minmax(0,1fr));
  }
}

/* ============================= */
/* Laptop height constraints     */
/* ============================= */
@media (max-height: 800px){
  header{ padding-block: .5rem; }
  .calculator{ padding: .75rem; }
  .display{ max-height: 18vh; }
  .site-footer{ padding: .5rem; }
}

/* ============================= */
/* Width-constrained laptops     */
/* ============================= */
@media (max-width: 1280px){
  .calculator{
    --key-size: clamp(44px, 9cqw, 96px);
    --key-gap:  clamp(6px, 0.9cqw, 12px);
  }
}

/* ============================= */
/* Container-based refinements   */
/* ============================= */
@container (min-width: 900px){
  .keypad{ gap: clamp(0.6rem, 0.8vw, 1rem); }
  .convert-section, .final-buttons{ gap: clamp(0.6rem, 0.8vw, 1rem); }
}

/* OVERRIDE: keep 4 columns even when container is narrow */
@container (max-width: 520px){
  .convert-section,
  .final-buttons{
    grid-template-columns: repeat(4, minmax(0,1fr));
  }
}

/* ============================= */
/* DESKTOP OVERRIDE: stop scaling
   with width and shrink height   */
/* ============================= */
@media (min-width: 1024px){
  .calculator{
    /* fixed width on normal / large screens */
    max-width: 740px;

    /* fixed key size & gap: no cqw, no width scaling */
    --key-size: 36px;
    --key-gap: 6px;
  }

  .convert-section button,
  .final-buttons button{
    /* fixed heights: no cqw scaling */
    min-height: 32px;
    padding: 8px;
    font-size: 0.9rem;
  }
}
