.cloud-fab {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 60;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 8px 12px 6px;
  font-family: "Pixelify Sans", monospace;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
  color: #27306a;
  background: #fff;
  border: 4px solid #27306a;
  box-shadow: 4px 4px 0 #27306a;
  cursor: pointer;
  animation: fabFloat 2.4s steps(4) infinite;
}

.cloud-fab:hover {
  background: #ffe3ef;
}

.cloud-fab:active {
  box-shadow: 1px 1px 0 #27306a;
  translate: 3px 3px;
}

.cf-cloud {
  width: 60px;
  height: 24px;
  background: url("../assets/cloud.png") center / 100% 100% no-repeat;
  image-rendering: pixelated;
}

@keyframes fabFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.cloud-win {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 10px;
  background: rgba(39, 48, 106, 0.6);
  overflow-y: auto;
}

.cloud-win[hidden] {
  display: none;
}

.cw {
  width: min(880px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background: #fff8fd;
  color: #27306a;
  border: 5px solid #27306a;
  box-shadow: 8px 8px 0 #27306a;
  font-family: "Pixelify Sans", monospace;
  animation: cwIn 0.3s steps(5);
}

@keyframes cwIn {
  from { transform: translateY(24px) scale(0.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.cw-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #5b82f5;
  border-bottom: 5px solid #27306a;
  flex-wrap: wrap;
}

.cw-title {
  flex: 1 1 auto;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 2px 2px 0 #27306a;
}

.cw-tabs {
  display: flex;
  gap: 6px;
}

.cw-tabs button,
.cw-x,
.cw-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 1px;
  color: #27306a;
  background: #fff;
  border: 3px solid #27306a;
  box-shadow: 3px 3px 0 #27306a;
  padding: 5px 12px;
  cursor: pointer;
}

.cw-tabs button.on {
  background: #ffc2dc;
}

.cw-tabs button:hover,
.cw-x:hover,
.cw-btn:hover {
  background: #ffe3ef;
}

.cw-x:active,
.cw-btn:active,
.cw-tabs button:active {
  box-shadow: 0 0 0 #27306a;
  translate: 3px 3px;
}

.cw-pane {
  padding: 12px;
}

.cw-pane[hidden] {
  display: none;
}

.cw-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
}

.hud-name {
  padding: 2px 8px;
  background: #ffc2dc;
  border: 3px solid #27306a;
}

.hud-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-bar i {
  position: relative;
  display: block;
  width: 96px;
  height: 14px;
  background: #fff;
  border: 3px solid #27306a;
  overflow: hidden;
}

.hud-bar i b {
  position: absolute;
  inset: 0 auto 0 0;
  width: 50%;
  background: #ff7aa8;
  transition: width 0.2s steps(4);
}

.hud-bar.xp i b {
  background: #5b82f5;
}

.hud-coins {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-coins span {
  width: 12px;
  height: 12px;
  background: #ffd666;
  border: 3px solid #27306a;
}

.cw-avatar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cw select,
.cw input[type="text"],
.cw textarea {
  font-family: inherit;
  font-size: 15px;
  color: #27306a;
  background: #fff;
  border: 3px solid #27306a;
  padding: 5px 8px;
  border-radius: 0;
}

.cw select:focus,
.cw input:focus,
.cw textarea:focus {
  outline: none;
  background: #eaf0ff;
}

.cw-stage {
  position: relative;
  border: 4px solid #27306a;
  box-shadow: 4px 4px 0 #27306a;
  background: #8fdc7e;
  line-height: 0;
}

.cw-stage canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 384 / 224;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: pointer;
}

.cw-dialog {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 10px 12px;
  line-height: 1.35;
  background: #fff;
  border: 4px solid #27306a;
  box-shadow: 4px 4px 0 #27306a;
  cursor: pointer;
  animation: dlgIn 0.2s steps(3);
}

.cw-dialog[hidden] {
  display: none;
}

@keyframes dlgIn {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.cw-dialog b {
  display: block;
  margin-bottom: 3px;
  color: #3f5fd0;
  font-size: 14px;
  letter-spacing: 1px;
}

.cw-dialog p {
  margin: 0;
  font-size: 16px;
}

.cw-dialog em {
  display: block;
  margin-top: 4px;
  font-style: normal;
  font-size: 12px;
  color: #6f78b8;
  animation: blinkTxt 1s steps(2) infinite;
}

@keyframes blinkTxt {
  50% { opacity: 0; }
}

.cw-help {
  margin: 8px 0 0;
  font-size: 13px;
  color: #4a5499;
}

.cw-pad {
  display: none;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.pad-dirs {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 4px;
}

.pad-dirs button,
.pad-act button {
  font-family: inherit;
  font-weight: 700;
  color: #27306a;
  background: #fff;
  border: 3px solid #27306a;
  box-shadow: 3px 3px 0 #27306a;
  touch-action: none;
  user-select: none;
}

.pad-dirs button:active,
.pad-act button:active {
  background: #ffc2dc;
}

.pad-dirs [data-dir="up"] { grid-column: 2; grid-row: 1; }
.pad-dirs [data-dir="left"] { grid-column: 1; grid-row: 2; }
.pad-dirs [data-dir="down"] { grid-column: 2; grid-row: 2; }
.pad-dirs [data-dir="right"] { grid-column: 3; grid-row: 2; }

.pad-act {
  display: flex;
  gap: 8px;
  grid-column: 3;
}

.pad-act button {
  width: 64px;
  height: 52px;
  font-size: 13px;
}

@media (hover: none), (max-width: 720px) {
  .cw-pad {
    display: grid;
  }
}

.cw-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.cw-box {
  padding: 10px;
  background: #fff;
  border: 4px solid #27306a;
  box-shadow: 4px 4px 0 #27306a;
  min-width: 0;
}

.cw-box h3 {
  margin: 0 0 8px;
  font-size: 15px;
  letter-spacing: 2px;
  color: #3f5fd0;
}

.cw-quests {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cw-quests li {
  display: grid;
  gap: 3px;
  padding: 6px 8px;
  font-size: 14px;
  background: #eaf0ff;
  border: 3px solid #27306a;
}

.cw-quests li.ready {
  background: #fff3b8;
  animation: readyPulse 0.8s steps(2) infinite;
}

.cw-quests li.done {
  background: #d8f5d0;
  text-decoration: line-through;
  opacity: 0.75;
}

@keyframes readyPulse {
  50% { background: #ffe27a; }
}

.q-bar {
  height: 8px;
  background: #fff;
  border: 2px solid #27306a;
}

.q-bar b {
  display: block;
  height: 100%;
  background: #5b82f5;
}

.chat-log {
  height: 150px;
  overflow-y: auto;
  padding: 6px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.3;
  background: #f3f6ff;
  border: 3px solid #27306a;
}

.chat-log p {
  margin: 0 0 3px;
  overflow-wrap: anywhere;
}

.chat-log .who {
  font-weight: 700;
  color: #3f5fd0;
}

.chat-log .me .who {
  color: #d04a7c;
}

.chat-log .sys {
  color: #7a6f00;
  font-weight: 600;
}

.cw-form {
  display: flex;
  gap: 6px;
}

.cw-form input {
  flex: 1;
  min-width: 0;
}

.jr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.jr-form {
  display: grid;
  gap: 8px;
  align-content: start;
}

.jr-form textarea {
  width: 100%;
  min-height: 170px;
  resize: vertical;
  line-height: 1.35;
}

.jr-moods {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.jr-moods button {
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  color: #27306a;
  background: #fff;
  border: 3px solid #27306a;
  padding: 3px 9px;
  cursor: pointer;
}

.jr-moods button.on {
  background: #ffc2dc;
  box-shadow: 3px 3px 0 #27306a;
}

.jr-count {
  font-size: 12px;
  color: #6f78b8;
}

.jr-list {
  display: grid;
  gap: 8px;
  align-content: start;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.jr-entry {
  padding: 8px 10px;
  background: #fff;
  border: 3px solid #27306a;
  box-shadow: 3px 3px 0 #27306a;
  animation: dlgIn 0.25s steps(3);
}

.jr-entry header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 700;
  color: #3f5fd0;
}

.jr-entry p {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.jr-entry button {
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  color: #d04a7c;
  background: #fff;
  border: 2px solid #d04a7c;
  padding: 1px 6px;
  cursor: pointer;
}

.jr-empty {
  padding: 14px;
  font-size: 15px;
  text-align: center;
  color: #6f78b8;
  border: 3px dashed #aab6ef;
}

@media (max-width: 720px) {
  .cw-cols,
  .jr-grid {
    grid-template-columns: 1fr;
  }

  .cw-avatar {
    margin-left: 0;
  }

  .cloud-fab {
    left: 10px;
    bottom: 10px;
  }

  .hud-bar i {
    width: 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cloud-fab,
  .cw,
  .cw-dialog,
  .jr-entry {
    animation: none;
  }
}
