﻿:root {
  --bg-main: #060b14;
  --bg-surface: rgba(15, 23, 38, 0.72);
  --bg-card: #0f1a2c;
  --text-main: #e7eef9;
  --text-muted: #a6b3c8;
  --accent: #1ec7b0;
  --line-soft: rgba(143, 167, 206, 0.24);
  --shadow-soft: 0 12px 34px rgba(2, 8, 20, 0.52);
  --shadow-strong: 0 28px 72px rgba(0, 0, 0, 0.6);
  --radius-xl: 28px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", "Noto Sans Thai", "Segoe UI", "Tahoma", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 18% 14%, rgba(48, 96, 153, 0.25), transparent 40%),
    radial-gradient(circle at 84% 20%, rgba(26, 126, 112, 0.2), transparent 38%),
    linear-gradient(145deg, #070d17 0%, #050a13 45%, #04070e 100%);
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(24px);
  z-index: -1;
  opacity: 0.5;
}

.orb-1 {
  width: 320px;
  height: 320px;
  top: -100px;
  left: -70px;
  background: radial-gradient(circle at 30% 30%, rgba(79, 122, 198, 0.8), rgba(45, 66, 113, 0.35));
}

.orb-2 {
  width: 380px;
  height: 380px;
  right: -120px;
  bottom: -150px;
  background: radial-gradient(circle at 40% 40%, rgba(44, 176, 154, 0.62), rgba(18, 62, 76, 0.34));
}

.app {
  width: min(960px, calc(100vw - 32px));
  margin: 34px auto 46px;
}

.app-header {
  margin-bottom: 20px;
  position: relative;
}

.app-header p {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: clamp(0.98rem, 1.8vw, 1.06rem);
  text-align: center;
}

.subtitle-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.subtitle-row p {
  margin: 0;
}

.info-btn {
  min-height: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 0;
  border: 0;
  background: transparent;
  color: #d9e8ff;
  line-height: 0;
  box-shadow: none;
  display: grid;
  place-items: center;
}

.info-icon {
  width: 18px;
  height: 18px;
  display: block;
}

.info-icon circle,
.info-icon line {
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.info-icon circle:last-child {
  fill: currentColor;
  stroke: none;
}

.info-btn:hover {
  transform: translateY(-1px);
  box-shadow: none;
  filter: brightness(1.12);
}

.info-btn:focus-visible {
  outline: none;
  box-shadow: none;
}

.info-flyout {
  position: absolute;
  left: 50%;
  top: calc(100% - 2px);
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(124, 150, 196, 0.35);
  background: rgba(13, 24, 42, 0.98);
  color: #dbe8fb;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45);
  z-index: 220;
}

.info-flyout p {
  margin: 0;
  text-align: left;
  font-size: 0.92rem;
  line-height: 1.45;
}

.info-flyout p + p {
  margin-top: 8px;
}

.info-flyout.is-hidden {
  display: none;
}

.logo-title {
  margin: 0 0 6px;
  display: flex;
  justify-content: center;
}

.app-logo {
  display: block;
  width: min(246px, 54.5vw);
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  grid-template-areas:
    "direction category"
    "random shuffle"
    "search toggle";
  gap: 10px;
  align-items: end;
  padding: 12px;
  border-radius: var(--radius-xl);
  border: 1px solid rgba(123, 149, 188, 0.26);
  background: var(--bg-surface);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  width: min(680px, 100%);
  margin: 0 auto;
  position: relative;
  z-index: 80;
}

.control-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.direction-field {
  grid-area: direction;
}

.category-field {
  grid-area: category;
}

.control-random {
  grid-area: random;
  width: 100%;
}

.control-shuffle {
  grid-area: shuffle;
  width: 100%;
}

.control-search {
  grid-area: search;
  position: relative;
  z-index: 90;
  min-width: 0;
}

.control-toggle {
  grid-area: toggle;
  justify-self: end;
  width: fit-content;
}

.search-toggle-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}

.search-toggle-row .control-search,
.search-toggle-row .control-toggle {
  grid-area: auto;
}

.search-toggle-row .control-toggle {
  width: 100%;
  justify-self: stretch;
}

.control-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #b8c7df;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

select,
button {
  min-height: 46px;
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 0.94rem;
  font-weight: 600;
}

select {
  background: rgba(21, 34, 56, 0.88);
  color: var(--text-main);
  border-color: rgba(143, 167, 206, 0.24);
}

.direction-select {
  padding-left: 12px;
  color: transparent;
  text-shadow: none;
  text-indent: -9999px;
  overflow: hidden;
  white-space: nowrap;
  background-image:
    url("assets/flags/gb.svg"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath fill='%239fb6d6' d='M4.1 2.2l1-1 5.8 5.8-5.8 5.8-1-1L8.9 7z'/%3E%3C/svg%3E"),
    url("assets/flags/th.svg");
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-size: 22px 16px, 12px 12px, 22px 16px;
  background-position: left 12px center, left 44px center, left 62px center;
}

.direction-select[data-direction="thai-to-english"] {
  background-image:
    url("assets/flags/th.svg"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath fill='%239fb6d6' d='M4.1 2.2l1-1 5.8 5.8-5.8 5.8-1-1L8.9 7z'/%3E%3C/svg%3E"),
    url("assets/flags/gb.svg");
}

.direction-select option {
  color: var(--text-main);
  text-indent: 0;
}

.search-box {
  position: relative;
  z-index: 90;
  width: 100%;
}

.search-input {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(143, 167, 206, 0.24);
  border-radius: var(--radius-md);
  background: rgba(21, 34, 56, 0.88);
  color: var(--text-main);
  padding: 10px 12px 10px 38px;
  font-size: 0.94rem;
  font-weight: 600;
}

.search-input::placeholder {
  color: #98a9c4;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #9fb6d6;
  font-size: 0.9rem;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid rgba(123, 149, 188, 0.35);
  border-radius: 12px;
  background: rgba(13, 24, 42, 0.98);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.45);
  z-index: 9999;
}

.search-results.is-hidden {
  display: none;
}

.search-result-item {
  width: 100%;
  border: 0;
  border-bottom: 1px solid rgba(123, 149, 188, 0.16);
  border-radius: 0;
  box-shadow: none;
  text-align: left;
  color: #dce8fb;
  background: transparent;
  padding: 10px 12px;
  font-weight: 600;
}

.search-result-item:last-child {
  border-bottom: 0;
}

.search-result-item:hover,
.search-result-item:focus-visible {
  background: rgba(38, 63, 98, 0.62);
  transform: none;
  filter: none;
  box-shadow: none;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(143, 167, 206, 0.24);
  background: rgba(21, 34, 56, 0.88);
  color: #d7e3f6;
  cursor: pointer;
}

.toggle span {
  white-space: nowrap;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

select:focus-visible,
button:focus-visible,
.search-input:focus-visible,
.card:focus-visible,
.toggle:has(input:focus-visible) {
  outline: none;
  box-shadow: 0 0 0 3px rgba(30, 199, 176, 0.28);
}

button {
  color: #052922;
  background: linear-gradient(135deg, #38dbc6, var(--accent));
  box-shadow: 0 9px 22px rgba(17, 160, 145, 0.32);
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.24s ease, filter 0.24s ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(19, 177, 160, 0.4);
  filter: brightness(1.04);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
  filter: none;
}

.card-wrap {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: relative;
  z-index: 1;
}

.card-stage {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
}

.nav-btn {
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.55rem;
  line-height: 1;
  color: #052922;
}

.nav-btn span {
  transform: translateY(-1px);
}

.card {
  position: relative;
  width: 100%;
  min-height: 340px;
  perspective: 1300px;
  border-radius: var(--radius-xl);
  cursor: pointer;
  will-change: transform, opacity;
}

.card-inner {
  position: relative;
  width: 100%;
  min-height: 340px;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.2, 0.75, 0.3, 1);
}

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

.card.no-flip-transition .card-inner {
  transition: none;
}

.bookmark-star {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 2;
  color: #ffe083;
  font-size: 1.28rem;
  line-height: 1;
  font-weight: 800;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.bookmark-star.is-hidden {
  display: none;
}

.learned-check {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 2;
  color: #ffffff;
  font-size: 1.18rem;
  line-height: 1;
  font-weight: 900;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.learned-check.is-hidden {
  display: none;
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 34px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--line-soft);
  background:
    linear-gradient(165deg, rgba(17, 30, 50, 0.96), rgba(12, 22, 38, 0.93)),
    var(--bg-card);
  box-shadow: var(--shadow-strong);
  backface-visibility: hidden;
}

.card-back {
  transform: rotateY(180deg);
}

.face-label {
  display: grid;
  place-items: center;
  width: 34px;
  height: 24px;
}

.flag-icon {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid rgba(220, 232, 255, 0.45);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.card-text {
  margin: 0;
  text-align: center;
  line-height: 1.45;
  white-space: pre-wrap;
}

.card-text.thai,
.card-text.english {
  font-size: clamp(1.8rem, 4.8vw, 2.7rem);
  font-weight: 750;
  letter-spacing: 0.01em;
}

.card-text.thai.with-sub {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45em;
  font-size: initial;
  font-weight: initial;
}

.card-text.thai.with-sub .thai-main {
  display: block;
  font-size: clamp(1.8rem, 4.8vw, 2.7rem);
  font-weight: 750;
  letter-spacing: 0.01em;
}

.card-text.thai.with-sub .thai-sub {
  display: block;
  font-size: clamp(1.02rem, 2.9vw, 1.38rem);
  font-weight: 620;
  color: #b8f5ea;
  letter-spacing: 0.01em;
}

.card-text.thai.with-sub .speak-btn {
  margin-top: 0.38rem;
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
  color: #d7fff8;
  border: 1px solid rgba(124, 235, 221, 0.44);
  background: rgba(20, 66, 77, 0.9);
  box-shadow: none;
}

.card-text.thai.with-sub .speak-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(5, 18, 36, 0.45);
  filter: brightness(1.06);
}

.card-text.thai.with-sub .speak-btn.is-hidden {
  display: none;
}

.card-meta {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.secondary-btn {
  min-width: 170px;
  color: #c8f7ef;
  background: rgba(24, 52, 69, 0.9);
  border: 1px solid rgba(82, 177, 199, 0.34);
  box-shadow: none;
}

.secondary-btn:hover {
  box-shadow: 0 9px 18px rgba(8, 20, 38, 0.45);
}

.stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.learned-info,
.card-info {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.93rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.learned-info {
  color: #b7f3e8;
}

.success-toast {
  position: fixed;
  left: 50%;
  top: 25%;
  bottom: auto;
  transform: translateX(-50%) scale(1);
  width: min(640px, calc(100vw - 20px));
  padding: 16px 20px;
  border-radius: 18px;
  border: 1px solid rgba(150, 248, 229, 0.58);
  background:
    radial-gradient(circle at 18% 20%, rgba(62, 153, 132, 0.22), transparent 40%),
    linear-gradient(160deg, rgba(30, 70, 98, 0.97), rgba(16, 39, 65, 0.96));
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.5),
    0 0 28px rgba(68, 230, 197, 0.22);
  text-align: center;
  z-index: 5000;
  opacity: 1;
  transition: opacity 0.28s ease, transform 0.32s cubic-bezier(0.18, 0.88, 0.32, 1.18);
  pointer-events: none;
}

.success-toast.is-hidden {
  opacity: 0;
  transform: translateX(-50%) scale(0.86);
}

.success-toast-title {
  margin: 0;
  font-size: clamp(1.2rem, 2.6vw, 1.55rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #f3fffb;
  text-shadow: 0 2px 10px rgba(35, 230, 186, 0.22);
}

.success-toast-text {
  margin: 8px 0 0;
  color: #dbfff6;
  font-size: clamp(1rem, 2.1vw, 1.22rem);
  font-weight: 750;
  line-height: 1.34;
}

@media (max-width: 800px) {
  .app {
    margin-top: 20px;
  }

  .controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    grid-template-areas:
      "direction category"
      "random shuffle";
    padding: 12px;
  }

  .search-toggle-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .card,
  .card-inner {
    min-height: 290px;
  }

  .card-face {
    padding: 24px;
  }

  .nav-btn {
    width: 58px;
    height: 58px;
    font-size: 1.7rem;
  }
}

@media (max-width: 560px) {
  .controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    grid-template-areas:
      "direction category"
      "random shuffle";
  }

  .card-actions {
    width: 100%;
    justify-content: stretch;
  }

  .card-actions .secondary-btn {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
    min-height: 44px;
    padding: 9px 10px;
    font-size: 0.9rem;
  }

  .app-logo {
    width: min(184px, 49vw);
  }

  .card-stage {
    grid-template-columns: 60px minmax(0, 1fr) 60px;
    gap: 10px;
  }

  .card {
    width: min(100%, 420px);
    justify-self: center;
    min-height: 236px;
  }

  .card-inner {
    min-height: 236px;
  }

  .card-face {
    padding: 18px;
    gap: 8px;
  }

  .card-wrap {
    margin-top: 18px;
    gap: 10px;
  }

  .card-text.thai,
  .card-text.english {
    font-size: clamp(1.42rem, 6vw, 2rem);
    line-height: 1.34;
  }

  .card-text.thai.with-sub .thai-main {
    font-size: clamp(1.42rem, 6vw, 2rem);
  }

  .card-text.thai.with-sub .thai-sub {
    font-size: clamp(0.92rem, 3.4vw, 1.14rem);
  }

  .card-text.thai.with-sub .speak-btn {
    width: 34px;
    height: 34px;
    min-height: 34px;
    font-size: 0.9rem;
  }

  .nav-btn {
    width: 60px;
    height: 60px;
    font-size: 1.8rem;
  }

  .card-meta {
    flex-direction: column;
    align-items: stretch;
  }

  .stats {
    align-items: center;
  }
}

@media (max-width: 480px) {
  .app {
    width: calc(100vw - 12px);
  }

  .controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    grid-template-areas:
      "direction category"
      "random shuffle";
    gap: 8px;
    border-radius: 20px;
    padding: 10px;
  }

  .category-field,
  .control-shuffle,
  .search-toggle-row .control-toggle {
    min-width: 0;
  }

  .search-toggle-row {
    gap: 8px;
  }

  #randomBtn,
  #shuffleBtn {
    min-height: 42px;
    padding: 10px;
  }

  .control-label {
    font-size: 0.78rem;
  }

  .card-stage {
    grid-template-columns: 56px minmax(0, 1fr) 56px;
    gap: 8px;
  }

  .card {
    width: min(100%, 360px);
    min-height: 220px;
  }

  .card-inner {
    min-height: 220px;
  }

  .card-face {
    padding: 16px;
  }

  .card-actions {
    gap: 8px;
  }

  .card-actions .secondary-btn {
    flex: 1 1 calc(50% - 6px);
    min-height: 42px;
    padding: 8px;
    font-size: 0.88rem;
  }

  .nav-btn {
    width: 56px;
    height: 56px;
    font-size: 1.65rem;
  }
}






