:root {
  --atp-blue: #5481c1;      /* the "T" in the ATP logo */
  --bg-blue: #1f3a5f;       /* darker blue behind the characters */
  --panel: rgba(14, 30, 52, 0.88);
  --line: rgba(84, 129, 193, 0.55);
  --text-dim: #b9c9df;
  --error: #ffcf66;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-blue);
  color: #fff;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#rain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Logo, upper-left */
.site-header {
  position: relative;
  z-index: 2;
  padding: 16px 20px 0;
  pointer-events: none;
}

.logo-link {
  pointer-events: auto;
  display: inline-block;
  width: clamp(190px, 20vw, 270px);
}

.logo-link img {
  display: block;
  width: 100%;
  height: auto;
  /* Soft shadow keeps the logo readable over the falling characters. */
  filter: drop-shadow(0 0 6px rgba(15, 30, 50, 0.95)) drop-shadow(0 0 14px rgba(15, 30, 50, 0.8));
  transition: filter 0.25s ease;
}

.logo-link:hover img,
.logo-link:focus-visible img {
  filter:
    drop-shadow(0 0 3px rgba(0, 0, 0, 0.9))
    drop-shadow(0 4px 12px rgba(0, 0, 0, 0.85));
}

.logo-link:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 6px;
  border-radius: 6px;
}

/* Calculator, centered */
.content {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - 110px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 16px 3rem;
  pointer-events: none; /* let the mouse reach the canvas outside the panel */
}

/* Flip card: front holds the calculator, back holds the CIDR reference. */
.flip {
  pointer-events: auto;
  width: min(520px, 100%);
  perspective: 1600px;
}

.flip-inner {
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.flip.flipped .flip-inner { transform: rotateY(180deg); }

.face {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.75rem 1.75rem 1.5rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* The back sits on top of the front and matches its size; the list scrolls inside it. */
.face-back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem 1rem;
}

/* Icon buttons (help and back) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  color: var(--text-dim);
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.icon-btn:hover { color: #fff; background: rgba(84, 129, 193, 0.3); }

.icon-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
  color: #fff;
}

.back-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.back-btn { margin-left: -4px; }

h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.ref-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
}

.ref-scroll:focus-visible { outline: 2px solid #fff; }

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 0.95rem;
}

.ref-table th {
  position: sticky;
  top: 0;
  background: #142a47;
  color: var(--text-dim);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--line);
}

.ref-table td {
  padding: 0.3rem 0.9rem;
  border-bottom: 1px solid rgba(84, 129, 193, 0.15);
}

.ref-table th:not(:first-child),
.ref-table td:not(:first-child) { text-align: right; }

h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.intro {
  margin: 0 0 1.25rem;
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.4;
}

.field { margin-bottom: 1rem; }

label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.95rem;
}

input[type="text"],
input[type="date"],
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 1.05rem;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 6px;
}

input[type="text"]::placeholder { color: rgba(185, 201, 223, 0.55); }

input[type="text"]:focus,
input[type="date"]:focus,
select:focus {
  outline: none;
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(84, 129, 193, 0.6);
}

input[aria-invalid="true"] { border-color: var(--error); }

.hint, .error {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  line-height: 1.35;
}

.hint { color: var(--text-dim); }
.error { color: var(--error); }

.btn {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: rgba(84, 129, 193, 0.25);
  border: 1px solid var(--atp-blue);
  border-radius: 6px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn:hover:not(:disabled) { background: rgba(84, 129, 193, 0.45); }

.btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.btn-primary {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.75rem 1rem;
  font-size: 1.05rem;
  background: var(--atp-blue);
}

.btn-primary:hover:not(:disabled) { background: #6a94d0; }

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

/* Results */
.results {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.45rem 1rem;
  margin: 0;
}

.summary dt {
  color: var(--text-dim);
  font-weight: 600;
}

.summary dd {
  margin: 0;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 1.02rem;
  word-break: break-word;
}

.note {
  margin: 0.9rem 0 0;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
  line-height: 0;
}

/* Reset sits at the far right of the button row. */
.reset-btn { margin-left: auto; }

.status {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.ip-list {
  margin: 0.9rem 0 0;
  max-height: 320px;
  overflow: auto;
  padding: 0.6rem 0.75rem;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 0.92rem;
  line-height: 1.45;
}

.ip-list:focus-visible { outline: 2px solid #fff; }

[hidden] { display: none !important; }

@media (max-width: 480px) {
  .ref-table { font-size: 0.78rem; }
  .ref-table th, .ref-table td { padding-left: 0.4rem; padding-right: 0.4rem; }
  .face { padding: 1.25rem 1.1rem; }
  .face-back { padding: 0.9rem 0.9rem; }
  h1 { font-size: 1.45rem; }
  .content { min-height: calc(100vh - 90px); align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .logo-link img, .btn, .icon-btn, .flip-inner, .seg-btn, .tab { transition: none; }
}

.status:empty { display: none; }

/* ---------- Hours calculator additions ---------- */

.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.title-row .icon-btn { margin-top: 0.2rem; margin-right: -4px; }

/* Calculator type tabs */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0.6rem 0 0.9rem;
  border-bottom: 1px solid var(--line);
}

.tab {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  padding: 0.6rem 0.5rem 0.55rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.tab:hover { color: #fff; background: rgba(84, 129, 193, 0.15); }
.tab[aria-selected="true"] { color: #fff; border-bottom-color: var(--atp-blue); }
.tab:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }

/* Inputs that hold times and dates use the monospace face like the reference IP box. */
input[type="date"] {
  color-scheme: dark;
  min-height: 2.75rem;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.75;
}

select {
  font-family: inherit;
  font-size: 0.95rem;
  color-scheme: dark;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23b9c9df' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
}

select option { background: #142a47; color: #fff; }

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Settings row */
.options {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.option-label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.option select { padding-top: 0.5rem; padding-bottom: 0.5rem; }

/* Segmented buttons (clock format, AM/PM) */
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  flex: 0 0 auto;
}

.seg-btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dim);
  background: none;
  border: none;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn:hover { color: #fff; background: rgba(84, 129, 193, 0.3); }
.seg-btn[aria-pressed="true"] { color: #fff; background: var(--atp-blue); }
.seg-btn:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }

.time-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.time-row .time-input { flex: 1 1 auto; min-width: 0; }
.ampm .seg-btn { padding: 0 0.75rem; }

/* 24-hour mode hides the AM/PM buttons on the hours tab. */
.clock-24 #panel-hours .ampm { display: none; }

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.label-text { font-weight: 600; font-size: 0.95rem; }
.optional { font-weight: 400; color: var(--text-dim); font-size: 0.85rem; }

.link-btn {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: #9dbbe6;
  background: none;
  border: none;
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
  cursor: pointer;
}

.link-btn:hover { color: #fff; text-decoration: underline; }
.link-btn:focus-visible { outline: 2px solid #fff; }
.link-btn:disabled { opacity: 0.45; cursor: not-allowed; text-decoration: none; }

/* Breaks */
.breaks { display: grid; gap: 0.5rem; }
.breaks:empty { display: none; }

.break-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.break-row input { flex: 1 1 auto; min-width: 0; }

.break-unit {
  color: var(--text-dim);
  font-size: 0.88rem;
  white-space: nowrap;
}

.break-row .icon-btn { flex: 0 0 auto; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.6rem 0 0;
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--text-dim);
  cursor: pointer;
}

.check input { width: 1rem; height: 1rem; accent-color: var(--atp-blue); margin: 0; }

/* Time between dates */
.dt-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 0.5rem;
}

.swap-row {
  display: flex;
  justify-content: center;
  margin: -0.4rem 0 0.2rem;
}

.swap-row .icon-btn { border-radius: 6px; }

/* Results */
.big {
  margin: 0 0 0.9rem;
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.big .sub {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 0;
}

/* Back of card */
.ref-notes {
  padding: 0.75rem 0.9rem 0.25rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text-dim);
}

.ref-notes h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: #fff;
}

.ref-notes p { margin: 0 0 0.6rem; }
.ref-notes strong { color: #fff; font-weight: 600; }

.ref-table th:nth-child(3),
.ref-table td:nth-child(3) { text-align: left; padding-left: 1.5rem; border-left: 1px solid rgba(84, 129, 193, 0.3); }

.offscreen {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

@media (max-width: 480px) {
  .options { grid-template-columns: 1fr; }
  .dt-row { grid-template-columns: 1fr; }
  .big { font-size: 1.6rem; }
  .tab { font-size: 0.88rem; padding-left: 0.25rem; padding-right: 0.25rem; }
}
