/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .72rem 1.15rem; border-radius: 11px; border: 1px solid transparent;
  font: inherit; font-weight: 700; font-size: .93rem; cursor: pointer;
  transition: transform .15s, background .15s, border-color .15s, box-shadow .15s;
  text-decoration: none; min-height: 44px;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 6px 18px rgba(37, 99, 235, .22); }
.btn-primary:hover { background: var(--brand-strong); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: transparent; color: var(--brand); padding-inline: .5rem; }
.btn-danger { background: transparent; color: var(--red-600); border-color: color-mix(in srgb, var(--red-600) 40%, transparent); }
.btn-small { padding: .4rem .7rem; min-height: 34px; font-size: .82rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

/* Cards and grids */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.4rem; box-shadow: var(--shadow-sm);
}
.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tool-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.category-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

.tool-card, .category-card, .article-card, .tip-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.3rem; box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s, border-color .2s;
  display: flex; flex-direction: column; gap: .6rem; min-width: 0;
}
.tool-card:hover, .category-card:hover, .article-card:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--brand);
}
.tool-card h3, .category-card h3, .article-card h3 { margin: 0; font-size: 1.03rem; }
.tool-card h3 a, .article-card h3 a { color: var(--text); }
.tool-card p, .category-card p, .article-card p { color: var(--muted); font-size: .89rem; margin: 0; }
.card-icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); flex-shrink: 0;
}
.category-card { border-top: 3px solid var(--brand); }
.category-count { color: var(--muted); font-size: .8rem; font-weight: 700; }
.card-link { margin-top: auto; font-size: .85rem; font-weight: 700; }
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .55rem;
  border-radius: 999px; background: var(--brand-soft); color: var(--brand);
  font-size: .72rem; font-weight: 750; letter-spacing: .02em;
}
.badge-neutral { background: var(--bg-soft); color: var(--muted); }

/* Search */
.search-wrap { position: relative; width: 100%; max-width: 640px; }
.search-box {
  display: flex; align-items: center; gap: .6rem; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 14px; padding: .4rem .5rem .4rem 1rem;
  box-shadow: var(--shadow-sm);
}
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring); }
.search-box > svg { color: var(--muted); flex-shrink: 0; }
.search-box input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; padding: .55rem 0;
}
.search-box input::placeholder { color: var(--muted); }
.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: .5rem; max-height: min(60vh, 480px); overflow-y: auto;
}
.search-list-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 750; margin: .4rem .5rem; }
.search-result {
  display: flex; align-items: center; gap: .7rem; padding: .6rem; border-radius: 10px;
  color: var(--text); text-decoration: none;
}
.search-result:hover, .search-result.is-active { background: var(--brand-soft); text-decoration: none; }
.search-result-icon { color: var(--brand); display: grid; place-items: center; }
.search-result-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.search-result-name { font-weight: 700; font-size: .92rem; }
.search-result-meta { color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-recent {
  display: block; width: 100%; text-align: left; padding: .45rem .6rem; border: 0;
  background: transparent; color: var(--text-soft); border-radius: 8px; cursor: pointer; font: inherit; font-size: .88rem;
}
.search-recent:hover { background: var(--brand-soft); }
.search-hint { color: var(--muted); font-size: .85rem; padding: .5rem; margin: 0; }
.search-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .3rem; padding: 1.5rem; color: var(--muted); }
.search-empty svg { color: var(--brand); }
.search-inline { width: 100%; max-width: 420px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field label, .field-label { font-size: .85rem; font-weight: 700; color: var(--text-soft); }
.field-hint { font-size: .76rem; color: var(--muted); }
input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"], input[type="time"], input[type="search"], textarea, select {
  width: 100%; min-height: 44px; padding: .62rem .75rem; border: 1px solid var(--border-strong);
  border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-size: .95rem;
}
textarea { min-height: 130px; resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { outline: 3px solid var(--ring); outline-offset: 1px; border-color: var(--brand); }
input[aria-invalid="true"] { border-color: var(--red-600); }
.form-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.1rem; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--text-soft); }
.checkbox-row input { width: 18px; min-height: 18px; accent-color: var(--brand); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0; }
legend { font-weight: 700; padding: 0 .4rem; }

/* Tool workspace */
.tool-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 1.4rem; align-items: start; }
.tool-layout.reversed { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); }
.tool-panel { padding: clamp(1.1rem, 3vw, 1.8rem); }
.tool-panel h2 { font-size: 1.3rem; margin-bottom: 1rem; }
.output-panel { min-height: 180px; }
.result-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 1.2rem;
}
[data-tone="error"] .result-card { border-color: color-mix(in srgb, var(--red-600) 50%, transparent); background: color-mix(in srgb, var(--red-600) 6%, var(--surface)); }
[data-tone="success"] .result-card { border-color: color-mix(in srgb, var(--green-600) 45%, transparent); }
[data-tone="warning"] .result-card { border-color: color-mix(in srgb, var(--amber-500) 55%, transparent); }
.result-title { margin-bottom: .8rem; color: var(--brand); }
.result-list { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .45rem 1rem; margin: 0; align-items: baseline; }
.result-list dt { color: var(--muted); font-size: .88rem; }
.result-list dd { margin: 0; font-weight: 750; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.result-heading { grid-column: 1 / -1; color: var(--text) !important; font-weight: 750; margin-top: .5rem; }
.result-note { margin: 1rem 0 0; font-size: .84rem; color: var(--muted); border-top: 1px dashed var(--border); padding-top: .8rem; }
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty-state svg { color: var(--brand); margin-bottom: .5rem; }
.empty-state strong { display: block; color: var(--text); margin-bottom: .25rem; }

/* Tables / rows */
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th { text-align: left; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; padding: .4rem .4rem .6rem; }
.data-table td { padding: .35rem .4rem; border-top: 1px solid var(--border); }
.data-table input, .data-table select { min-height: 38px; padding: .4rem .55rem; font-size: .88rem; }
.row-actions { display: flex; gap: .3rem; }
.list-item {
  display: flex; gap: .8rem; align-items: flex-start; justify-content: space-between;
  padding: .9rem 0; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-item-body { min-width: 0; }
.list-item-title { font-weight: 700; }
.list-item-meta { color: var(--muted); font-size: .82rem; }
.list-actions { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.progress { height: 9px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); border-radius: inherit; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .8rem; }
.stat {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: .9rem;
}
.stat strong { display: block; font-size: 1.55rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .78rem; }

/* Tabs and toggles */
.tab-list { display: flex; flex-wrap: wrap; gap: .4rem; border-bottom: 1px solid var(--border); margin-bottom: 1.2rem; }
.tab-button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 700;
  padding: .6rem .9rem; border-bottom: 3px solid transparent; cursor: pointer;
}
.tab-button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.segmented { display: inline-flex; flex-wrap: wrap; gap: .3rem; background: var(--bg-soft); padding: .3rem; border-radius: 12px; }
.segmented button {
  border: 0; background: transparent; color: var(--text-soft); font: inherit; font-weight: 700;
  padding: .45rem .8rem; border-radius: 9px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }

/* Flashcards */
.flashcard {
  perspective: 1000px; width: 100%; min-height: 230px; cursor: pointer; background: transparent;
  border: 0; padding: 0; text-align: left; color: inherit;
}
.flashcard-inner { position: relative; width: 100%; min-height: 230px; transform-style: preserve-3d; transition: transform .5s; }
.flashcard.is-flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0; backface-visibility: hidden; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: .6rem; padding: 1.4rem;
  border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  background: var(--surface);
}
.flashcard-face.back { transform: rotateY(180deg); background: var(--brand-soft); }
.flashcard-face span { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 750; }
.flashcard-face strong { font-size: 1.15rem; overflow-wrap: anywhere; }

/* FAQ and articles */
.faq-item { border-bottom: 1px solid var(--border); padding: .4rem 0; }
.faq-item:last-child { border-bottom: 0; }
.faq-item summary { cursor: pointer; font-weight: 700; padding: .8rem 0; list-style-position: inside; }
.faq-item p { color: var(--text-soft); margin-bottom: 1rem; }
.article-card time { color: var(--muted); font-size: .78rem; }

/* Reserved ad slots (disabled by default) */
.ad-slot {
  min-height: 90px; border: 2px dashed var(--border-strong); border-radius: 12px;
  display: grid; place-items: center; color: var(--muted); font-size: .8rem;
  background: var(--surface-2); margin: 1.5rem 0;
}

/* Offline / misc */
.offline-note { display: none; }
html[data-offline="true"] .offline-note { display: block; }
.chip-list { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: 0; }
.chip-list a, .chip-list span {
  display: inline-flex; padding: .3rem .7rem; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--border); font-size: .82rem; color: var(--text-soft);
}
.chip-list a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.notice {
  border-left: 4px solid var(--brand); background: var(--brand-soft);
  padding: .9rem 1rem; border-radius: 0 10px 10px 0; font-size: .9rem; margin: 1rem 0;
}
.notice-warning { border-left-color: var(--amber-500); background: color-mix(in srgb, var(--amber-500) 10%, var(--surface)); }
.notice-error { border-left-color: var(--red-600); background: color-mix(in srgb, var(--red-600) 8%, var(--surface)); }
.countdown-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; }
.countdown-cell { text-align: center; background: var(--navy-900); color: #fff; border-radius: 12px; padding: .8rem .3rem; }
.countdown-cell strong { display: block; font-size: clamp(1.3rem, 4vw, 2rem); font-variant-numeric: tabular-nums; }
.countdown-cell span { font-size: .7rem; opacity: .75; text-transform: uppercase; letter-spacing: .08em; }
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; }
.day-column { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: .6rem; min-width: 0; }
.day-column h4 { font-size: .8rem; margin-bottom: .5rem; }
.slot { background: var(--brand-soft); color: var(--text); border-radius: 8px; padding: .45rem; font-size: .75rem; margin-bottom: .4rem; overflow-wrap: anywhere; }
.slot button { float: right; border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 .2rem; }
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.bar-chart div { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .3rem; font-size: .68rem; color: var(--muted); }
.bar-chart span { display: block; width: 100%; max-width: 42px; background: linear-gradient(180deg, var(--sky-500), var(--blue-600)); border-radius: 5px 5px 0 0; min-height: 2px; }
.timer-display { font-size: clamp(3.5rem, 12vw, 6rem); font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.timer-ring-text { color: var(--muted); text-align: center; }
