:root {
  --bg: #f6f1e8;
  --ink: #1e2522;
  --muted: #65716c;
  --panel: #fffaf0;
  --line: #d9d0bd;
  --green: #1f7a5a;
  --green-dark: #155640;
  --amber: #d6932a;
  --red: #b44839;
  --blue: #2f6f8e;
  --accent: #1f7a5a;
  --accent-dark: #155640;
  --accent-soft: rgba(31, 122, 90, 0.35);
  --shadow: 0 18px 48px rgba(40, 44, 38, 0.14);
}

body[data-theme="sky"] {
  --accent: #2f6f8e;
  --accent-dark: #20506b;
  --accent-soft: rgba(47, 111, 142, 0.34);
}

body[data-theme="peach"] {
  --accent: #c76343;
  --accent-dark: #94482f;
  --accent-soft: rgba(199, 99, 67, 0.34);
}

body[data-theme="grape"] {
  --accent: #7655a6;
  --accent-dark: #563c7d;
  --accent-soft: rgba(118, 85, 166, 0.34);
}

body[data-theme="honey"] {
  --accent: #c8871f;
  --accent-dark: #936115;
  --accent-soft: rgba(200, 135, 31, 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    "Yu Gothic UI",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    sans-serif;
  background:
    linear-gradient(180deg, rgba(47, 111, 142, 0.12), transparent 34rem),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.7rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  min-height: 36px;
  padding: 8px 14px;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
}

.loader,
.control-panel {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.86);
  box-shadow: var(--shadow);
}

.loader {
  padding: 14px;
  margin-bottom: 18px;
  border-radius: 8px;
}

.search-form,
.source-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 10px;
}

.search-form {
  margin-bottom: 10px;
}

.search-form input,
.source-form input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  outline: none;
}

.search-form input:focus,
.source-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 142, 0.18);
}

.search-form button,
.source-form button,
.button-grid button {
  min-height: 48px;
  color: #fff;
  background: var(--accent);
  border-radius: 6px;
  font-weight: 700;
}

.search-form button:hover,
.source-form button:hover,
.button-grid button:hover {
  background: var(--accent-dark);
}

.message {
  min-height: 22px;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.message.error {
  color: var(--red);
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.player-panel {
  min-width: 0;
}

.player-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  width: 100%;
  min-height: 260px;
  background: #111;
  border: 1px solid #151515;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

#player,
#player iframe {
  width: 100%;
  height: 100%;
}

.player-shade {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(7, 9, 8, 0.72);
  transition: opacity 160ms ease;
  pointer-events: auto;
}

.player-shade.ready {
  background: rgba(7, 9, 8, 0.18);
}

.player-shade.has-image {
  padding: 18px;
  background: rgba(7, 9, 8, 0.74);
}

.shade-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.36);
}

.player-shade span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 104px;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
  font-weight: 700;
}

.player-shade.hidden {
  opacity: 0;
  pointer-events: none;
}

.shade-image.hidden,
.player-shade span.hidden {
  display: none;
}

.control-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  border-radius: 8px;
}

.state-block {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.state-value {
  min-height: 34px;
  color: var(--red);
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.1;
}

.state-value.playing {
  color: var(--accent);
}

.hold-target {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 88px;
  padding: 14px;
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.hold-target:focus {
  outline: 3px solid rgba(47, 111, 142, 0.28);
  outline-offset: 2px;
}

.hold-target.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.keycap {
  display: inline-grid;
  place-items: center;
  min-width: 76px;
  min-height: 48px;
  padding: 0 12px;
  color: inherit;
  border: 1px solid currentColor;
  border-bottom-width: 4px;
  border-radius: 7px;
  font-weight: 900;
}

#holdText {
  font-size: 1.35rem;
  font-weight: 800;
}

.theme-picker {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.color-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.color-dot {
  display: block;
  aspect-ratio: 1;
  width: 100%;
  min-height: 42px;
  border: 2px solid transparent;
  border-radius: 999px;
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.78),
    0 4px 12px rgba(30, 37, 34, 0.14);
}

.color-dot[aria-pressed="true"] {
  border-color: var(--ink);
}

.color-dot.mint {
  background: #1f7a5a;
}

.color-dot.sky {
  background: #2f6f8e;
}

.color-dot.peach {
  background: #c76343;
}

.color-dot.grape {
  background: #7655a6;
}

.color-dot.honey {
  background: #c8871f;
}

.message-image-panel {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.image-actions {
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 8px;
}

.file-button,
.image-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 12px;
  color: #fff;
  background: var(--accent);
  border-radius: 6px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.file-button:hover,
.image-actions button:hover {
  background: var(--accent-dark);
}

.image-actions button {
  background: var(--red);
}

.image-actions button:hover {
  background: #8e3329;
}

.image-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

#messageImageInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.meters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.meters > div {
  min-height: 84px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.meters strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1.2;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button-grid .wide {
  grid-column: 1 / -1;
  background: var(--amber);
}

.button-grid .wide:hover {
  background: #a56d16;
}

body.holding .player-frame {
  outline: 4px solid var(--accent-soft);
  outline-offset: 4px;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .control-panel {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 12px;
  }

  .search-form,
  .source-form {
    grid-template-columns: 1fr;
  }

  .player-frame {
    min-height: 196px;
  }

  .meters {
    grid-template-columns: 1fr;
  }
}
